-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Error when accessing properties on globalThis
with the same name of a global variable
#58345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think what you should actually be seeing here is a circularity error |
Note that the code above has actually valid use cases. I spotted it while doing let SuppressedError = globalThis.SuppressedError ?? class SuppressedError extends Error {
// ...
} |
Hello @nicolo-ribaudo. Attempting to use the variable before declaration will result in a ReferenceError. This is known as the "temporal dead zone," where the variable exists in the scope but cannot be accessed. But, When you declare a variable with On the other hand, when you declare a variable with So, in your case, when you try to do However, if you use |
In the example above no variables are in temporal dead zone -- you can try running that code and it does not error. |
FWIW, this error is reported here and this is the In a sense, this is by design as the code is somewhat explicit about it. But perhaps this should be revisited. |
π Search Terms
globalThis redefined error script property does not exist
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?noImplicitAny=false&ts=5.5.0-beta#code/DYUwLgBAlgdgbgQ2FAJgRggXggc2AewCMkAVACygGcA6WRZdAbgChRIBPLXA44cq2vCSo0LNhABeXPEVIUadYSgBMLIA
π» Code
π Actual behavior
Property 'invalid1' does not exist on type 'typeof globalThis'.
π Expected behavior
It should either complain about both
invalid1
andinvalid2
, or neitherAdditional information about the issue
It only happens in scripts and not in modules (if I add
export {}
, there are no reported errors).The text was updated successfully, but these errors were encountered: