Categories
JavaScript Answers

How to extend TypeScript Global object in node.js?

Spread the love

To extend TypeScript Global object in node.js, we add a type declaration file.

For instance, we write

declare module NodeJS {
  interface Global {
    spotConfig: any;
  }
}

to add a type declaration in vendor.d.ts to add the Global interface into the project type definition with the properties we want to add to the global interface.

Therefore, we can use the spotConfig global variable without type errors.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *