Categories
TypeScript Answers

How to declare third party modules with TypeScript?

Spread the love

Sometimes, we want to declare third party modules with TypeScript.

In this article, we’ll look at how to declare third party modules with TypeScript.

How to declare third party modules with TypeScript?

To declare third party modules with TypeScript, we use the declare keyword.

For instance, we write

declare module "foo-module" {
  function foo(): void;
  export = foo;
}

in a .d.ts file in our TypeScript project to declare the foo-module module and its members.

Then we can import the module without errors by writing

import * as foo from "foo-module";
foo();

in our code.

Conclusion

To declare third party modules with TypeScript, we use the declare keyword.

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.