If the returned variable is not a local variable, any script that requires it will show “error-type” in auto-complete.
-
Using global var
-
Using local var
-
System info:
13th Gen Intel(R) Core™ i7-13700K
32.0 GB
NVIDIA GeForce RTX 4060 Ti
If the returned variable is not a local variable, any script that requires it will show “error-type” in auto-complete.
Using global var
Using local var
System info:
13th Gen Intel(R) Core™ i7-13700K
32.0 GB
NVIDIA GeForce RTX 4060 Ti
Thanks for the report! We’ll follow up when there’s any update on the issue.
Hi there, I’m taking a look at this report now. I’ve attempted to make the setup you have here in a few configurations. With Luau’s current type inference system in production, I see that the inferred type of mod
is *error-type*
either way, regardless of whether the script contents were being required have local or not. The reason for this is made apparent if you enable non-strict or strict mode typechecking, where you can actually see the error that causes this:
The error says “Cannot require module game.Workspace.Script: Module is not a ModuleScript. It cannot be required.” This behavior here is expected, and the solution is that you should use ModuleScripts for code that you would like to import with require
. If you attempt to run a program, e.g. if your requiring script has something like the following, you’ll see that at runtime this require will fail because the argument is not a ModuleScript
.
local mod = require(workspace.Script)
print(mod.hi)
It does look like when I enable the New Type Solver Beta that the Luau team is working on, I do see the behavioral difference that you’re noting here, where requiring a Script
(i.e. not a ModuleScript
instance) produces the error with both a local and a global, but when it happens to be a local, we somehow manage to give you the type it would have if it were able to be required. It still won’t work at runtime though, so the behavior with local in the New Type Solver Beta is the bug. I’ll investigate that further, and put together a fix, but again, the solution for you is that you actually want to use ModuleScript
, and not Script
.