As a Roblox developer, it is currently too hard to house exported types under other modules. As of currently there is no way to retrieve the exported types produced by a module in-bulk rather than one by one. I am currently working on a game framework, which is to be entirely typechecked using in-built Roblox typechecking. This has proven to be a very tedious and manual process. We have a ModuleScript structure for types similar to the following:
SharedTypes.lua
├── DataServiceTypes.lua
├── NetworkServiceTypes.lua
└── UIServiceTypes.lua
Ideally, we want every type accessible via a single require to SharedTypes
, but we want them defined in their associated script too so we don’t clutter unrelated types together. IE: we want the following code to be possible given the right setup:
local SharedTypes = require([PathToSharedTypesModule])
local foo: SharedTypes.NetworkService.bar
However, to achieve this effect, we can’t simply export ‘NetworkService’ from the SharedTypes script because types can only be referenced one by one, not as a group. We instead need to manually define each of these types again in our SharedTypes
script, such as the following:
export type NetworkService_foo = require(script.NetworkServiceTypes).foo
export type NetworkService_bar = require(script.NetworkServiceTypes).bar
export type NetworkService_taz = require(script.NetworkServiceTypes).taz
Yuck, how ugly! It can’t even use the dot operator either because that can’t be used in type-names. And quite unmaintainable too; because plugins cannot easily access all of the types defined in a script without parsing the source manually; we have to manually define each of these types in SharedTypes
every time we make add/remove a type, or we must keep a log of these type-names elsewhere for a plugin to automate.
If Roblox is able to address this issue, it would improve my development experience because it would allow us to decrease development time significantly by reducing the time spent manually defining each of these types for a second time.