microsoft / microsoft/TypeScript

Access `global` as a type

Open
#14,052 9 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Since https://github.com/Microsoft/TypeScript/wiki/What%27s-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:

  1. inconsistency with what is actually the global namespace
  2. requiring the declaration of global types multiple times in case it's used as a "real global" or from window. (browsers) or global. (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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the proposal alongside dom.d.ts and node.d.ts, then read the related issue #12902 to distinguish this request from global-scope additions. Done means TypeScript provides a usable global namespace type so declarations such as window and global can reference it without duplicating global types.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.