-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathglobal-this.d.ts
More file actions
24 lines (17 loc) · 732 Bytes
/
global-this.d.ts
File metadata and controls
24 lines (17 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
Declare locally scoped properties on `globalThis`.
When defining a global variable in a declaration file is inappropriate, it can be helpful to define a `type` or `interface` (say `ExtraGlobals`) with the global variable and then cast `globalThis` via code like `globalThis as unknown as ExtraGlobals`.
Instead of casting through `unknown`, you can update your `type` or `interface` to extend `GlobalThis` and then directly cast `globalThis`.
@example
```
import type {GlobalThis} from 'type-fest';
type ExtraGlobals = GlobalThis & {
readonly GLOBAL_TOKEN: string;
};
const globalToken = (globalThis as ExtraGlobals).GLOBAL_TOKEN;
//=> string
```
@category Type
*/
export type GlobalThis = typeof globalThis;
export {};