How do you type cast require()?

If I am requiring a module, what type is returned?

local module: ModuleScript = require(path.to.module) seems incorrect because ModuleScript is an instance which would be path.to.module and not what require actually returns AFAIK

The documentation explains it as the variable being directly set to the table that was returned, in that case would I just cast it to the format of the table?

1 Like

require basically turns the module into what it returns.

ModuleScript:

return "hi"

Script:

local msg = require(path.to.module)
print(msg) --> "hi"
1 Like

They’re asking about the typing of module scripts, not what require does.

To OP, I believe that at least for functions, it automatically handles the types for them, but I can’t get it to work with other table entries like strings.

2 Likes

You don’t need to set the type to get autocomplete, which I think is what you’re using the type for.

Yes. The require is the type of whatever the module script returns.

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