"Unknown global" type error using --!strict

Reproduction Steps

a = 1

Expected Behavior
In my case, I have to declare my variable without local due to this error:

Actual Behavior
I get:

Type Error: (2,1) Unknown global 'a'

Issue Area: Studio
Issue Type: Other
Impact: High
Frequency: Constantly

1 Like

Since this is intentional, a feature request would need to be made instead. It’s a good idea to group state into tables or separate code into multiple modules.

It doesn’t seem to me to be intentional, because currently I just can’t have global variables using --!strict.

Yes, the idea is that global variables shouldn’t be used. There’s no way to disambiguate between a typo on a local variable reassignment and a new global variable assignment, which is a reason the analyzer will report false positives like this.

If you read the OP, I can’t use local.
So in this case I also can’t use -!strict.
That’s why I opened a bug report.

I did read it. It’s intentional that using a global variable does this, you’d need to make a feature request or just use tables to group state. The 200 variable limit is rarely reached, so not factored into design decisions.

I do not agree.
So I understand it’s a bug.

Not only is this not a bug, but it cannot work the way that you want. Consider the following:

local myThing = 6
myThng = 7

If things worked the way you want, then this would not register as an error, despite being exactly the kind of error that Luau was created to avoid. Basically this not counting as an error would mostly defeat the point of Luau’s type checking.

The solution to your issue is to structure your code in a way where you don’t have 200 local variables. If you use good code structure you should not be running into that limit. If you’re really struggling I could suggest ways to change the code structure.


If Studio allows a global variable, but doesn’t allow it with -!strict, then this is indeed a bug.
Either Studio doesn’t allow global variables in any situation, or it allows it in all situations.

This would be an impractical stance to take. Existing Lua code out there contains a lot of global variables. If we took the above stance then that code would not be able to advantage of typechecking without completely migrating away from using those globals, where nonstrict mode is supposed to generally work with existing code.

1 Like

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