Skip to content

Instantly share code, notes, and snippets.

@n8jadams
Last active March 5, 2020 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n8jadams/27183f479f2a2c3f766c384e7aa71bb9 to your computer and use it in GitHub Desktop.
Save n8jadams/27183f479f2a2c3f766c384e7aa71bb9 to your computer and use it in GitHub Desktop.
In Typescript, use the global object in Node, or the window object in the browser
/* eslint-disable @typescript-eslint/no-explicit-any */
// Nodeland
interface ExtendedGlobal extends NodeJS.Global {
someGlobalKey: string
}
export const extendedGlobal: ExtendedGlobal = global as any
// Browserland
interface ExtendedWindow extends Window {
someWindowKey: string
}
export const extendedWindow: ExtendedWindow = window as any
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment