Access `global` as a type
See original GitHub issueSince https://github.com/Microsoft/TypeScript/wiki/What’s-new-in-TypeScript#augmenting-globalmodule-scope-from-modules it’s been possible to augment the global
from a module. However, in TypeScript definitions (such as dom.d.ts
or node.d.ts
) we’re left to create our own “globals”. This results in two issue:
- inconsistency with what is actually the global namespace
- requiring the declaration of global types multiple times in case it’s used as a “real global” or from
window.
(browsers) orglobal.
(node)
Instead of this, it’d be really nice to access TypeScript’s global
as a type. For instance, in dom.d.ts
we could do:
declare var window: global
Or in node.d.ts
:
declare var global: global
I couldn’t see any previous issues, but it’s partially related to things like https://github.com/Microsoft/TypeScript/issues/12902 - the difference though is that those issues seems to be tracking adding variables to the TypeScript global scope whereas this would be using the global scope as a type to define these variables themselves.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:9 (7 by maintainers)
Top GitHub Comments
Random update: We pretty much know we want to do this (and talked about it when we added
import
types), we’re just waiting for https://github.com/tc39/proposal-global (the proposal referenced in #12902) to stabilize with a name for the global-thing, so we can use the same name for the type lookup.This is now supported by using
typeof globalThis
in a type position.