NPM Package doesn't have Types

Viewed 3599

I'm transforming a small express api to use TypeScript, but some of the packages don't have a @types/ so when I import them I get a TS2307 error.

Is there something I can do to resolve the error? Or maybe type it myself, depending on the package complexity. One example is express-bearer-token(found here)

1 Answers

The quick way is to create a globals.d.ts file and add the line:

declare module "express-bearer-token";

This will treat express-bearer-token as a JS module without typings. More information about that here.

From there, you can start adding more typings yourself if you wish. You can find some information about writing your own definitions here.

Related