Categories
TypeScript Answers

How to declare a type globally in a project with TypeScript?

Spread the love

Sometimes, we want to declare a type globally in a project with TypeScript.

In this article, we’ll look at how to declare a type globally in a project with TypeScript.

How to declare a type globally in a project with TypeScript?

To declare a type globally in a project with TypeScript, we can use the declare statement in a .d.ts file.

For instance, we add

declare module "my-module" {
  export declare class Something {
    public something: number;
  }
}

into a .d.ts file into our TypeScript project folder to declare the types for the my-module module.

We declare that it has class Something and it has the something number instance property.

Conclusion

To declare a type globally in a project with TypeScript, we can use the declare statement in a .d.ts file.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.