Deno: Cannot access certain globalThis properties in .ts files

Created on 19 Jul 2019  路  4Comments  路  Source: denoland/deno

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

Most helpful comment

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

All 4 comments

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

@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.

@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.

https://github.com/Microsoft/TypeScript/pull/29332

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kyeotic picture kyeotic  路  3Comments

kitsonk picture kitsonk  路  3Comments

metakeule picture metakeule  路  3Comments

ry picture ry  路  3Comments

ry picture ry  路  3Comments