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.