DefinitelyTyped is a public repository of TypeScript declaration files for JavaScript packages. Installing a matching @types package lets the TypeScript compiler check third-party APIs without manually describing their types. section 2.3.3 section 15.3.4
Use DefinitelyTyped when a JavaScript dependency lacks the type information TypeScript needs:
- Install declarations as a development dependency with npm install --save-dev @types/package-name. section 2.3.3 section 15.3.4
- The package name normally combines @types/ with the JavaScript package name, such as @types/inquirer or @types/debug. section 2.3.3 section 15.3.4
- The compiler discovers declarations in node_modules/@types automatically, unless configuration redirects resolution or creates a conflict with custom declarations. section 15.3.4
Catching an unsupported API option
After installing @types/inquirer, adding badProperty: true to an Inquirer.js prompt causes tsc to report a type error. The declaration file exposes the package API to static checking, although the diagnostic may identify a related overload mismatch rather than naming the unsupported property directly. section 2.3.3
