diff --git a/types/globalthis/globalthis-tests.ts b/types/globalthis/globalthis-tests.ts new file mode 100644 index 0000000000..2c292ed1ff --- /dev/null +++ b/types/globalthis/globalthis-tests.ts @@ -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 diff --git a/types/globalthis/implementation.d.ts b/types/globalthis/implementation.d.ts new file mode 100644 index 0000000000..ae78cc53a9 --- /dev/null +++ b/types/globalthis/implementation.d.ts @@ -0,0 +1,5 @@ +/** + * The `globalThis` object. + */ +declare const implementation: typeof globalThis; +export = implementation; diff --git a/types/globalthis/index.d.ts b/types/globalthis/index.d.ts new file mode 100644 index 0000000000..59ba3767bc --- /dev/null +++ b/types/globalthis/index.d.ts @@ -0,0 +1,29 @@ +// Type definitions for globalthis 1.0 +// Project: https://github.com/ljharb/System.global#readme +// Definitions by: 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; + + /** + * The `globalThis` object. + */ + const implementation: typeof import('./implementation'); + + /** + * Installs the `globalThis` property onto the global object. + */ + function shim(): ReturnType; +} + +export = getGlobal; diff --git a/types/globalthis/polyfill.d.ts b/types/globalthis/polyfill.d.ts new file mode 100644 index 0000000000..13910ea5f2 --- /dev/null +++ b/types/globalthis/polyfill.d.ts @@ -0,0 +1,7 @@ +import implementation = require('./implementation'); + +/** + * Gets the `globalThis` object. + */ +declare function getPolyfill(): typeof implementation; +export = getPolyfill; diff --git a/types/globalthis/shim.d.ts b/types/globalthis/shim.d.ts new file mode 100644 index 0000000000..8b2280e873 --- /dev/null +++ b/types/globalthis/shim.d.ts @@ -0,0 +1,7 @@ +import implementation = require('./implementation'); + +/** + * Installs the `globalThis` property onto the global object. + */ +declare function shimGlobalThis(): typeof implementation; +export = shimGlobalThis; diff --git a/types/globalthis/tsconfig.json b/types/globalthis/tsconfig.json new file mode 100644 index 0000000000..bf5c313f6c --- /dev/null +++ b/types/globalthis/tsconfig.json @@ -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" + ] +} diff --git a/types/globalthis/tslint.json b/types/globalthis/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/globalthis/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }