feat: Add globalThis (#40096)

This commit is contained in:
ExE Boss 2019-11-05 18:07:36 +01:00 committed by Nathan Shively-Sanders
parent 3a19d3f7c9
commit 0410320f11
7 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,6 @@
import getGlobal = require('globalthis');
getGlobal(); // $ExpectType typeof globalThis
getGlobal.implementation; // $ExpectType typeof globalThis
getGlobal.getPolyfill; // $ExpectType () => typeof globalThis
getGlobal.shim; // $ExpectType () => typeof globalThis

5
types/globalthis/implementation.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
/**
* The `globalThis` object.
*/
declare const implementation: typeof globalThis;
export = implementation;

29
types/globalthis/index.d.ts vendored Normal file
View File

@ -0,0 +1,29 @@
// Type definitions for globalthis 1.0
// Project: https://github.com/ljharb/System.global#readme
// Definitions by: ExE Boss <https://github.com/ExE-Boss>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.4
/**
* Gets the `globalThis` object.
*/
declare function getGlobal(): typeof globalThis;
declare namespace getGlobal {
/**
* Gets the `globalThis` object.
*/
function getPolyfill(): ReturnType<typeof import('./polyfill')>;
/**
* The `globalThis` object.
*/
const implementation: typeof import('./implementation');
/**
* Installs the `globalThis` property onto the global object.
*/
function shim(): ReturnType<typeof import('./shim')>;
}
export = getGlobal;

7
types/globalthis/polyfill.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
import implementation = require('./implementation');
/**
* Gets the `globalThis` object.
*/
declare function getPolyfill(): typeof implementation;
export = getPolyfill;

7
types/globalthis/shim.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
import implementation = require('./implementation');
/**
* Installs the `globalThis` property onto the global object.
*/
declare function shimGlobalThis(): typeof implementation;
export = shimGlobalThis;

View File

@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es5"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"implementation.d.ts",
"index.d.ts",
"polyfill.d.ts",
"shim.d.ts",
"globalthis-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }