Skip to content
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

Cannot access certain globalThis properties in .ts files #2669

Closed
dev-nicolaos opened this issue Jul 19, 2019 · 4 comments · Fixed by #2984
Closed

Cannot access certain globalThis properties in .ts files #2669

dev-nicolaos opened this issue Jul 19, 2019 · 4 comments · Fixed by #2984

Comments

@dev-nicolaos
Copy link
Contributor

dev-nicolaos commented Jul 19, 2019

As discussed in #650 and #2368, in Deno window === globalThis. This can be verified by running the statement in the REPL.

However, if you create a file...

// test.ts
console.log(window === globalThis);

and run deno test.ts, the tsc will throw an error, complaining that:

error TS2367: This condition will always return 'false' since the types 'typeof globalThis' and 'Window' have no overlap.

This also prevents the ability to use things like globalThis.fetch, globalThis.addEventListener, and globalThis.onload in .ts files, even though this should be perfectly safe in Deno given that all these things work in ordinary .js files and the REPL.

Debug Info
Tested on Deno v0.12.0 running on Windows 10

@justjavac
Copy link
Contributor

@justjavac
Copy link
Contributor

TypeScript: "It's not a bug, it's a feature" 😂

@dev-nicolaos
Copy link
Contributor Author

dev-nicolaos commented Jul 19, 2019

@justjavac thanks for the posting the related issue. Looks like the workaround for now is an // @ts-ignore comment. It'd be nice if this could be solved by an adjustment to the runtime's tsconfig.json but I don't know TS well enough to know if that's even possible.

@justjavac
Copy link
Contributor

justjavac commented Jul 23, 2019

@dev-nicolaos However in TS v3.5 window is still declared as declare var window: Window; not as Window & typeof globalThis as described in globalThis's PR. Maybe, the TS team will plans to change it.

microsoft/TypeScript#29332

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants