How to add custom typings in TypeScript?

Sometimes, we want to add custom typings in TypeScript.

In this article, we’ll look at how to add custom typings in TypeScript.

How to add custom typings in TypeScript?

To add custom typings in TypeScript, we can add declare statements into .d.ts files into our project.

For instance, we write

declare module "some-js-lib" {
  export function hello(world: string): void;
}

to add typings for the some-js-lib module.

We add the hello function declaration into it so that the TypeScript compiler knows that the hello function is available in some-js-lib.

Conclusion

To add custom typings in TypeScript, we can add declare statements into .d.ts files into our project.