Skip to content

Instantly share code, notes, and snippets.

@adrienjoly
Created January 15, 2024 14:49
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 adrienjoly/e5b1b2f4b3b5f988eff2f155756841c9 to your computer and use it in GitHub Desktop.
Save adrienjoly/e5b1b2f4b3b5f988eff2f155756841c9 to your computer and use it in GitHub Desktop.
Typing a `globalThis` variable on Node.js, using TypeScript.
declare global {
// Note: It is crucial to note that [...] variables must only be declared using var
// cf https://copyprogramming.com/howto/using-globalthis-in-typescript
var myGlobalVariable: string;
}
// => `globalThis.myGlobalVariable` is properly typed as `string`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment