Categories
TypeScript Answers

How to add custom typings in TypeScript?

Spread the love

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.

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 *