Is there any way to create cyclic modulescript types?

Hello. I am trying to create a type modulescript with all of my oop types simply so I can have a global list of types instead of scattered everywhere.

First I tried this
image
and don’t get me wrong, it works, but I have to physically define every single type myself!

Ofc the roblox type wizard engineers thought of this, so you can type define with typeof to take all the methods off of you like so


ok so we can define types in all of our oop objects, can’t we just require them all and yoink them all in a type script?

well actually, yes we can
image

and ill just try and use OopObject2 in OopClass1’s modulescript aaaand…
image
uh oh! (understandably) roblox doesn’t allow cyclic module requires!

heres where my frustrations come in


in this video I show that you CAN have cyclic types, as long as they are all in the same script.

the implications for something like this existing for modulescripts is insane, it would make my life infinite times easier, it would things like intellisensed children types and component based objects easier by an INSANE amount.

is there any way you lovely devforum scripting support browsers can think of to get around this issue?

edit: if not can a regular on the devforum make a feature request for a method to extract only the exported types from a modulescript and not require the whole modulescript at runtime?

edit2: fixing a goof my cat made when he stepped on my keyboard

I don’t understand why your problem requires the ability to have a require() cycle nor any reason why one would want a require() cycle to be allowed.

simply for type definition, it gives me arthritis to do this in a type def module

languages like C# have type namespaces so you can have global types shared across all scripts. This makes it harder to do something like Unity’s component based gameobject logic.

I was wondering if there was any easier way to do something like that.
like if there was a way to get only exported type definitions from a module instead of straight loading it.

edit: and luau already has cyclic types, just they have to be confined within the same script, as shown here

1 Like

Did you find a solution to this? Felt like it was worth bumping, doubt I’m the only one with this problem.

1 Like

unfortunately no, the only solution I can imagine is using ScriptEditorService to hack in autocomplete for a certain type, but when anything dealing with typing at runtime comes out it will break

roblox really should add something similar to type namespaces instead of just using modulescripts

1 Like

Highly agree, would also be cool to at some point see classes added (without the use of metatables). Very unlikely, but I would love to see it.

decent idea but unfortunately luau is a multi-paradigm language, the support for classes are in metatables. and metatables are extremely powerful in class construction in general.

the only downside is inheritance…

to register a class “inheriting” from another class you would need to do something like this

local InheritingFrom = {}--yadda yadda
InheritingFrom.__index = InheritingFrom

local Module = setmetatable({}, InheritingFrom)
Module.__index = Module

function Module:Method()

end

function Module.new()
   local self = InheritingFrom.new()
   
   self.property = "index"

   return setmetatable(self, Module)
end

return Module

which can be kind of confusing

one year later bump… any new discoveries on how to go about this?