Careeroza
Types Packages
Installing @types
Packages written in plain JavaScript often have community types on DefinitelyTyped, published as @types/<package>. Install them as dev dependencies; TypeScript picks them up automatically.
Example
npm install express
npm install --save-dev @types/express @types/nodeExample output
added 2 packages, and audited 70 packages in 2s
When There are No Types
If a package has no types, TypeScript reports TS7016 "Could not find a declaration file for module". Options, best first:
- Check if a newer version ships types, or search
@types/<name>. - Write a small
.d.tsfor the parts you use (next page). - Last resort:
declare module "old-lib";in a.d.tsfile, which types everything from it asany.
| tsconfig option | Effect |
|---|---|
"types": ["node", "jest"] | only these global @types packages are included (faster, avoids clashes) |
"typeRoots" | folders to look for global type packages |
"skipLibCheck": true | do not type-check .d.ts files from libraries (faster builds, recommended) |