I have a mock setup here.
Module A
local module = {} -- root module, has basic types
export type Character = typeof(script.CharacterRig)
export type Tool = typeof(script.ToolSkeleton)
return module
Module B
local module = {} -- middle module dependent on root
local moduleA = require(moduleA)
export type House = typeof(script.HouseSkeleton)
return module
I want to do this.
Main Script
local module = {}
local moduleB = require(moduleB)
local house = model:Clone() :: ModuleB.House -- this is good
local owner = char :: moduleB.Character -- i cannot do this
return module
Essentially, I want to use one module and access all of the types inside it, even from its dependencies.
Attempted solutions
Attempted solutions
It’s solvable if I just require(moduleA) for my main script and use moduleA.Character
local module = {}
local moduleA = require(moduleA)
local moduleB = require(moduleB)
local house = model:Clone() :: ModuleB.House -- this is good
local owner = char :: moduleA.Character -- this is good
return module
but this is a mock case. In practice, I would like to have multiple type modules, and this makes it confusing to track.
It’s also solvable if I manually define out the types in moduleB,
local module = {} -- middle module dependent on root
local moduleA = require(moduleA)
export type Character = moduleA.Character
export type Tool = moduleA.Tool
export type House = typeof(script.HouseSkeleton)
return module
but that’s not realistic when type modules become huge and hard to maintain with version control.
In practice having them all type modules merged into one big type module but organized separately would be nice. This image demonstrates it. Note that not all required modules will be neatly sitting inside it.