liveBook · Manning

DefinitelyTyped

As explained in Essential TypeScript 5, Third Edition

Definitely Typed is a public repository of TypeScript type declarations for JavaScript packages.

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

How Essential TypeScript 5, Third Edition covers it

How deep it goes
Explains installation, automatic resolution, configuration conflicts, and compiler diagnostics without detailing declaration-file authoring.
Examples
Uses Inquirer.js and debug, with npm commands, tsconfig.json settings, traceResolution output, and an unsupported prompt property.
What it assumes
Assumes familiarity with npm, JavaScript packages, TypeScript compilation, and tsconfig.json configuration.
What you can do after
Apply it via npm by installing matching @types packages and use compiler diagnostics to catch incorrect JavaScript API calls.
How it connects
Connects npm, TypeScript declaration files, JavaScript packages, compiler configuration, and static type checking.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Essential TypeScript 5, Third Edition. The section links point to the parts of the book it draws on.