Namespace 'NodeJS' has no exported member 'Global'

Viewed 2848

I used to define global variables using the following code:

interface CustomNodeJSGlobal extends NodeJS.Global {
  myGlobalVariable: unknown
}

export { CustomNodeJSGlobal }

In Node 14, but when I installed @types/node (which is currently in the version 16) it throws me an error Namespace 'NodeJS' has no exported member 'Global'. How can I declare global variables in Node 16 and above?

1 Answers

With Node.js >= 16, I think NodeJS.Global type is no longer available, but you can declare it like:

type NodeJSGlobal = typeof global;
Related