Extending TypeScript Global object in node.js
As of node@16
the NodeJS.Global
interface has been removed in favor of globalThis
.
You can declare new global variable in a module file as:
declare global {
var NEW_GLOBAL: string;
}
And in a non-module file (no top-level import/export) as:
declare var NEW_GLOBAL: string;
Important note: variable must be declared as var
. let
or const
variables doesn't show up on globalThis
.
I saw this SO post and tried this:
You probably have something like vendor.d.ts
:
// some import
// AND/OR some export
declare module NodeJS {
interface Global {
spotConfig: any
}
}
Your file needs to be clean of any root level import
or exports
. That would turn the file into a module and disconnect it from the global type declaration namespace.
More : https://basarat.gitbooks.io/typescript/content/docs/project/modules.html