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.
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/lodashReal-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