TypeScript: Type Definitions

  • There are two main ways to get declarations for a library: Bundled and DefinitelyTyped.
  • To be able to show errors and hints from other packages, the compiler relies on declaration files. A declaration file provides all the type information about a library. This enables us to use javascript libraries like those on npm in our project.
  • Bundled - The library bundles its own declaration file. To check if a library has bundled types, look for an index.d.ts file in the project. Some libraries will have it specified in their package.json under the typings or types field.
  • DefinitelyTyped is a huge repository of declarations for libraries that don’t bundle a declaration file. To get declaration file from DefinitelyTyped run: 'yarn add --dev @types/react' or 'npm i --save-dev @types/react'.

Related concepts

Type Definitions

TypeScript: Type Definitions — Structure map

Clickable & Draggable!

TypeScript: Type Definitions — Related pages: