How can I refine a type in modulescript/fix module dependency?

Says I have 2 module like this and I want module2 to refine module.a to string.

Module1 script:

return { a = nil }

Module2 script:

local Module1 = require("./Module1")
Module1.a = "" -- still nil in the type hint

I am doing this because I have a module dependency which I cannot fix without doing this I think?
Here the module dependency loop:
module1 → module2 → module3 → module1

module1 need module2 to create a value and module2 get that value from module3 which module3 need that value from module1 so now I am precreating that empty value first in a seperate module to fill in the module1, that value is used for typechecking

i am kinda trying to do something similar like this

If it’s “still nil”, then there’s really only two possiblities:

  1. Your module scripts don’t exist on the same end of the network. The server, client, and even command line are all separate environments which all yield different copies of the same ModuleScript. Only requiring scripts from the same environment will see the changes made.

  2. The script that’s reading the value is reading it too early.

Try your best to redesign your approach if you encounter cyclic dependencies. The only ultimate solution is to avoid requiring the cyclic module while the module is being executed, so do it within a function. Module loaders would cache the results of a series of modules after the invocation of an initializing function

Hello thanks for responding it seem that I have confused you about the code, the value is not being nil but being represent as nil in the type hint, sorry for not making it clear.

I don’t think this is possible.
Since module script can be required by other module script so the typechecker prob won’t know what type to refine and will be default as the module that declared it. As for cyclic module dependency for only types, won’t be supported sadly The ability to require something only for its types · Issue #452 · luau-lang/luau · GitHub