Importing module types in a hierarchy

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.
image

silly take, but do you have the right path of your modules?

Could you clarify on what you mean by pathing?

Here is a place with the code setup demonstrating what I need help with.

LuauTypeHierarchy.rbxl (84.1 KB)

ahhh this

--!strict
local module = {}

local moduleA = require(script.TypesA)
local moduleB = require(script.TypesB) -- //didnt think you defined the module correctly

export type EngineEnum = "Default" | "Fixed" | "Adaptive"

return module

as well as having more i understand your view on having all modules to work as one - which is possible.

as a person who loves neat code and isnt keen with large amounts (losing concentration) and hard to retract back on code.

its hard to go by, u could just call all modules on the engine.

but things like this, i never tried cause you’re calling the module on itself - it needs a client or server. As a module cant be required in its own script. local moduleB = require(moduleB) - im not the best with modules.

but thats all i got - ill try and find a post, i think ive seen one similar to this.