Advertisement
Beginner TypeScript, Declaration Files

How do you get type definitions for a popular JavaScript library that doesn't ship its own types?

Short answer

Install the corresponding community-maintained package from DefinitelyTyped, prefixed with @types/ — TypeScript automatically discovers and uses these type packages from node_modules without any extra configuration.

Save TypeScript mock interview
Advertisement
AModel answer
Install the corresponding community-maintained package from DefinitelyTyped, prefixed with @types/ — TypeScript automatically discovers and uses these type packages from node_modules without any extra configuration.
npm install lodash
npm install --save-dev @types/lodash
Real-world example
Getting full type safety and autocomplete for a library like lodash or express that's written in plain JavaScript.
Likely follow-ups
  • How does TypeScript know to look in @types packages automatically?
Related topics