-
Notifications
You must be signed in to change notification settings - Fork 12.8k
globalThis property access errors are behind noImplicitAny, not noImplicitThis #30139
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
No complaints so far. I think this is fine where it is. |
Hi! Faced this issue |
Can you explain more about your expectations and usage?
|
@sandersn I have exactly that problem It worked fine in lower versions (ts 4.2.*) do you have any idea? |
@KevinGruber nothing comes to mind except maybe external changes to |
@KevinGruber I managed to remove this message with the property "noImplicitAny": false. ts 4.3.5 |
I am getting this error when bumping I have the following defined in my code:
|
@bennycode I had the same issue with exactly the same use case as yours. Seems that the latest @types/node has the following type definition file content
Seems that at some point it had a different content
What I ended up doing is this ( porting your changes ):
or
|
@mstaicu Where to put those definitions? in |
@hazemalabiad I declared the type definitions in my implementation file
|
Thanks for helping me @mstaicu. My problem is that Test: declare global {
function client(): APIClient;
}
global.client = new APIClient(APIClient.URL_DEMO, "global-demo-api-key"); Error:
Test: declare global {
client: APIClient;
}
global.client = new APIClient(APIClient.URL_DEMO, "global-demo-api-key"); Error:
Test: declare module globalThis {
function client(): APIClient;
}
global.client = new APIClient(APIClient.URL_DEMO, "global-demo-api-key"); Error:
I tried to use a getter and setter definition as these are supported since TS 3.6 but it also didn't help: Test: declare global {
get client(): APIClient;
} Error:
Test: declare module globalThis {
get client(): APIClient;
} Error:
You can find my attempts here: bennycode/ig-trading-api#288 |
@bennycode what about the following:
Then access |
Somehow, this only works when defining the following way: declare module global {
const MY_VAR: string;
} The following do not work: declare global { /* ... */ };
declare globalThis { /* ... */ };
declare module globalThis { /* ... */ }; Only |
Hello, sorry to revive this 2.5 years later, but I'm facing this issue with Node. declare var global: typeof globalThis; So even if I added the solution above in my |
Now that globalThis is available, top-level
this
also has a more precise type, and issues the normal noImplicitAny element access errors for unknown properties:We have a conflict: traditionally, "x has no index signature" errors are produced when noImplicitAny is on. Also traditionally, "this has type any" errors are produced when noImplicitThis is on.
Technically, top-level
this
no longer has type any, so it's technically correct to issue the errors from behind noImplicitAny. But people might expect to see them only when noImplicitThis is on instead.Let's discuss at the next design meeting.
The text was updated successfully, but these errors were encountered: