-
Notifications
You must be signed in to change notification settings - Fork 30.6k
[node] Added globalThis support to global
#44700
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
Merged
sheetalkamat
merged 10 commits into
DefinitelyTyped:master
from
JasonHK:node/global-this-support-for-global
May 21, 2020
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
045ec19
[node] Added `globalThis` support to `global`
JasonHK 1ddb139
[node] Fixed style issue
JasonHK 6708226
[window-or-global] Fixed the bug introduced by `globalThis` support …
JasonHK 5ad3d7c
[node] Moved those changes to TS3.5 to avoid fragmenting versions
JasonHK 68a0ebf
[node] Fixed the incorrect path
JasonHK 305cfd8
[node] Added tests for `globalThis` members
JasonHK fc665eb
Merge branch 'master' of https://github.com/DefinitelyTyped/Definitel…
JasonHK 70fa976
[node] Moved `globalThis` support for v12 to TS 3.4
JasonHK e8cb305
[window-or-global] Apply the changes suggested by @ExE-Boss
JasonHK 84bf705
[window-or-global] Update types/window-or-global/index.d.ts
JasonHK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| declare var global: NodeJS.Global; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| // NOTE: These definitions support NodeJS and TypeScript 3.2. | ||
| // This is requried to enable globalThis support for global in ts3.5 without causing errors | ||
| // This is requried to enable typing assert in ts3.7 without causing errors | ||
| // Typically type modifiations should be made in base.d.ts instead of here | ||
|
|
||
| /// <reference path="base.d.ts" /> | ||
|
|
||
| // tslint:disable-next-line:no-bad-reference | ||
| /// <reference path="../assert.d.ts" /> | ||
|
|
||
| // tslint:disable-next-line:no-bad-reference | ||
| /// <reference path="../globals.global.d.ts" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| declare var global: NodeJS.Global & typeof globalThis; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ////////////////////////////////////////////////////////////////////////// | ||
| /// `globalThis` Tests: https://node.green/#ES2020-features-globalThis /// | ||
| ////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| { | ||
| const isGlobal: NodeJS.Global = global; | ||
| const isGlobalThis: typeof globalThis = global; | ||
|
|
||
| const accessibleToGlobalThisMembers: true = global.RANDOM_GLOBAL_VARIABLE; | ||
| } | ||
|
|
||
| declare var RANDOM_GLOBAL_VARIABLE: true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| declare var global: NodeJS.Global; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,11 @@ | |
| "ts3.7/*" | ||
| ] | ||
| }, | ||
| ">=3.4.0-0": { | ||
| "*": [ | ||
| "ts3.4/*" | ||
| ] | ||
| }, | ||
| ">=3.2.0-0": { | ||
| "*": [ | ||
| "ts3.2/*" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| // NOTE: These definitions support NodeJS and TypeScript 3.2. | ||
| // This is requried to enable globalThis support for global in ts3.4 without causing errors | ||
| // This is requried to enable typing assert in ts3.7 without causing errors | ||
| // Typically type modifiations should be made in base.d.ts instead of here | ||
|
|
||
| /// <reference path="base.d.ts" /> | ||
|
|
||
| // tslint:disable-next-line:no-bad-reference | ||
| /// <reference path="../assert.d.ts" /> | ||
|
|
||
| // tslint:disable-next-line:no-bad-reference | ||
| /// <reference path="../globals.global.d.ts" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // NOTE: These definitions support NodeJS and TypeScript 3.4. | ||
|
|
||
| // NOTE: TypeScript version-specific augmentations can be found in the following paths: | ||
| // - ~/base.d.ts - Shared definitions common to all TypeScript versions | ||
| // - ~/index.d.ts - Definitions specific to TypeScript 2.1 | ||
| // - ~/ts3.4/base.d.ts - Definitions specific to TypeScript 3.4 | ||
| // - ~/ts3.4/index.d.ts - Definitions specific to TypeScript 3.4 with assert pulled in | ||
|
|
||
| // Reference required types from the default lib: | ||
| /// <reference lib="es2018" /> | ||
| /// <reference lib="esnext.asynciterable" /> | ||
| /// <reference lib="esnext.intl" /> | ||
| /// <reference lib="esnext.bigint" /> | ||
|
|
||
| // Base definitions for all NodeJS modules that are not specific to any version of TypeScript: | ||
| // tslint:disable-next-line:no-bad-reference | ||
| /// <reference path="../ts3.2/base.d.ts" /> | ||
|
|
||
| // TypeScript 3.5-specific augmentations: | ||
| /// <reference path="globals.global.d.ts" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| declare var global: NodeJS.Global & typeof globalThis; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // NOTE: These definitions support NodeJS and TypeScript 3.4. | ||
| // This is requried to enable typing assert in ts3.7 without causing errors | ||
| // Typically type modifiations should be made in base.d.ts instead of here | ||
|
|
||
| /// <reference path="base.d.ts" /> | ||
|
|
||
| // tslint:disable-next-line:no-bad-reference | ||
| /// <reference path="../assert.d.ts" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| ////////////////////////////////////////////////////////////////////////// | ||
| /// `globalThis` Tests: https://node.green/#ES2020-features-globalThis /// | ||
| ////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| const isGlobal: NodeJS.Global = global; | ||
| const isGlobalThis: typeof globalThis = global; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ////////////////////////////////////////////////////////////////////////// | ||
| /// `globalThis` Tests: https://node.green/#ES2020-features-globalThis /// | ||
| ////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| { | ||
| const isGlobal: NodeJS.Global = global; | ||
| const isGlobalThis: typeof globalThis = global; | ||
|
|
||
| const accessibleToGlobalThisMembers: true = global.RANDOM_GLOBAL_VARIABLE; | ||
| } | ||
|
|
||
| declare var RANDOM_GLOBAL_VARIABLE: true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| { | ||
| "files": [ | ||
| "index.d.ts", | ||
| "node-tests.ts", | ||
| "test/globals.ts" | ||
| ], | ||
| "compilerOptions": { | ||
| "module": "commonjs", | ||
| "target": "esnext", | ||
| "lib": [ | ||
| "es6", | ||
| "dom" | ||
| ], | ||
| "noImplicitAny": true, | ||
| "noImplicitThis": true, | ||
| "strictNullChecks": true, | ||
| "strictFunctionTypes": true, | ||
| "baseUrl": "../../../", | ||
| "typeRoots": [ | ||
| "../../../" | ||
| ], | ||
| "paths": { | ||
| "node": [ | ||
| "node/v12" | ||
| ] | ||
| }, | ||
| "types": [], | ||
| "noEmit": true, | ||
| "forceConsistentCasingInFileNames": true | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| { "extends": "dtslint/dt.json" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| declare var global: NodeJS.Global; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| // NOTE: These definitions support NodeJS and TypeScript 3.2. | ||
| // This is requried to enable globalThis support for global in ts3.5 without causing errors | ||
| // This is requried to enable typing assert in ts3.7 without causing errors | ||
| // Typically type modifiations should be made in base.d.ts instead of here | ||
|
|
||
| /// <reference path="base.d.ts" /> | ||
|
|
||
| // tslint:disable-next-line:no-bad-reference | ||
| /// <reference path="../assert.d.ts" /> | ||
|
|
||
| // tslint:disable-next-line:no-bad-reference | ||
| /// <reference path="../globals.global.d.ts" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| declare var global: NodeJS.Global & typeof globalThis; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ////////////////////////////////////////////////////////////////////////// | ||
| /// `globalThis` Tests: https://node.green/#ES2020-features-globalThis /// | ||
| ////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| { | ||
| const isGlobal: NodeJS.Global = global; | ||
| const isGlobalThis: typeof globalThis = global; | ||
|
|
||
| const accessibleToGlobalThisMembers: true = global.RANDOM_GLOBAL_VARIABLE; | ||
| } | ||
|
|
||
| declare var RANDOM_GLOBAL_VARIABLE: true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| // Type definitions for window-or-global 1.0 | ||
| // Project: https://github.com/purposeindustries/window-or-global | ||
| // Definitions by: vvakame <https://github.com/vvakame> | ||
| // Jason Kwok <https://github.com/JasonHK> | ||
| // ExE Boss <https://github.com/ExE-Boss> | ||
| // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
|
|
||
| /// <reference types="node" /> | ||
|
|
||
| declare var _: Window | typeof global; | ||
| declare const _: typeof self | typeof global; | ||
| export = _; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "private": true, | ||
| "types": "index", | ||
| "typesVersions": { | ||
| ">=3.4.0-0": { | ||
| "*": [ | ||
| "ts3.4/*" | ||
| ] | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /// <reference types="node" /> | ||
|
|
||
| declare const _: typeof globalThis & (typeof self | typeof global); | ||
| export = _; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "module": "commonjs", | ||
| "target": "esnext", | ||
| "lib": [ | ||
| "es6", | ||
| "dom" | ||
| ], | ||
| "noImplicitAny": true, | ||
| "noImplicitThis": true, | ||
| "strictNullChecks": true, | ||
| "strictFunctionTypes": true, | ||
| "baseUrl": "../../", | ||
| "typeRoots": [ | ||
| "../../" | ||
| ], | ||
| "types": [], | ||
| "noEmit": true, | ||
| "forceConsistentCasingInFileNames": true | ||
| }, | ||
| "files": [ | ||
| "index.d.ts", | ||
| "window-or-global-tests.ts" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| { "extends": "dtslint/dt.json" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import * as root from "window-or-global"; | ||
|
|
||
| if (Reflect.has(root, "location")) { | ||
| // $ExpectType Location | ||
| root.location; | ||
| } else if (Reflect.has(root, "process")) { | ||
| // $ExpectType Process | ||
| root.process; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.