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/node

Example 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:

  1. Check if a newer version ships types, or search @types/<name>.
  2. Write a small .d.ts for the parts you use (next page).
  3. Last resort: declare module "old-lib"; in a .d.ts file, which types everything from it as any.
tsconfig optionEffect
"types": ["node", "jest"]only these global @types packages are included (faster, avoids clashes)
"typeRoots"folders to look for global type packages
"skipLibCheck": truedo not type-check .d.ts files from libraries (faster builds, recommended)