Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM Package doesn't have Types

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)

like image 380
John Avatar asked Mar 22 '26 00:03

John


2 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.

like image 150
zeh Avatar answered Mar 24 '26 14:03

zeh


For daisyui

Create global.d.ts in the root directory

Add the below line

declare module "daisyui";

Note: Stop the server and re-start if you the server is running already.

like image 44
Anjan Talatam Avatar answered Mar 24 '26 14:03

Anjan Talatam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!