How do I forward declare global variables in strict mode? #912
Replies: 2 comments 1 reply
-
I'm able to get the typechecker to register declare thisGlobal: {
x: number,
y: number,
} which partially solves your issue. |
Beta Was this translation helpful? Give feedback.
-
I believe I've found a solution to this. The reason for at least some of the problem is that the type check for global assignment only checks the bindings for the current module, and not the current module's parent, which is where the type definition file puts its definitions. I'm not sure why defining global functions works, but presumably What I ended up doing was applying the fix I described in #867. This then allows me to declare globals inline by setting
...which is kind of ideal for my use case. In #867 I did say that even with the change, the code no longer compiled, but that doesn't seem to be the case any more. Which is nice! (Disclaimer: I'm still picking away at type errors and it's entirely possible that this has caused something else to go wrong which I haven't noticed yet...) |
Beta Was this translation helpful? Give feedback.
-
I have code which approximately does this:
The strict type checker:
a. complains about unknown global variables both times
b. can't tell what the type of
thisGlobal
is.I've tried defining the type of the global in my
.d.lua
file, but that's ignored --- presumably because globals defined there go into the immutable globals table rather than the mutable shadow globals table which assigning to _G affects.Is there any way around this?
(The two functions are in different chunks sharing the same global table, so using
local
isn't an option here.)Beta Was this translation helpful? Give feedback.
All reactions