How to get a LUAU custom type defined in another script?

In one modulescript I have a custom Luau type defined (among other things:)

local moduleA = {}

type AppartmentIventoryItem = {
	DateAquired : number;
	UserAcknowledged : boolean;
	Catagory : string;
	ItemId : string;
	Count : number;
	CustomAttributes : {};
}

...

return moduleA

In another module I would like to be able to define a variable that will hold this custom type

local moduleB = {}

local Variable : AppartmentIventoryItem?

return moduleB

Is there a way to reference this type defined in ModuleA from ModuleB? I’m having an issue where Roblox isn’t able to figure it out on it’s own and I would like to tell it what type this variable holds but can’t. Do I have to copy and paste the definition of this type into every script that uses it? I really don’t want to do that as making a single change will require me to make that change in many places.

You would have to export it using export type.

-- moduleA
export type MyClass = {
    foo: number,
    bar: boolean
}

-- moduleB
type MyClass = moduleA.MyClass
local myClass: MyClass

-- or reference directly
local myClass: moduleA.MyClass
1 Like

Dear god

I’m not sure why the method horrifies me so much but I’m glad you can do it at least. I guess it’s the implication that additional hidden data is being returned when you call require() that scares me

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.