forked from sindresorhus/type-fest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
global-this.d.ts
21 lines (15 loc) · 688 Bytes
/
global-this.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
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;
};
(globalThis as ExtraGlobals).GLOBAL_TOKEN;
```
@category Type
*/
export type GlobalThis = typeof globalThis;