Tool

Types finder for npm packages

Type an npm package name to see whether it ships its own types, whether a DefinitelyTyped package exists for it, and the line to install. The answer comes from the npm registry when you look it up.

What "ships its own types" means

A package ships its own types when its published files include .d.ts declaration files and its package.json tells TypeScript where they are: a types (or older typings) field, a types condition in its exports map, or typesVersions. Installing the package is then enough: tsc and your editor find the types, and there is nothing else to install. The types option page explains how those packages are found, and the publishing recipe shows the exports map from the author's side.

A package without types of its own often has a community package on DefinitelyTyped, published under the @types scope: @types/express for express, and @types/scope__name for a scoped package @scope/name. Install it as a development dependency. When neither exists, importing the package in a checked file under noImplicitAny is TS7016, and the fix is a short declaration of your own: a .d.ts file for an untyped package.

How it works

When you look a package up, your browser asks the public npm registry (registry.npmjs.org) for two documents: the package.json of the package's latest version, and the same for its @types package. The tool reads the types, typings, exports and typesVersions fields of the first, the version and any deprecation notice of both, and the license. Nothing else is sent, and nothing is stored; the privacy page says what the registry receives. The address bar keeps ?package= with the name, so a lookup can be shared.

To answer the same question by hand, in a terminal:

Terminal
npm view express types typings exports --json
npm view @types/express version deprecated

What it cannot see

  • Undeclared declaration files. TypeScript also finds an index.d.ts next to a package's main file without any field pointing at it. The registry's metadata does not list files, so such a package shows as "not declared". A deprecated @types package is the usual hint, and the tool says so.
  • Whether the types are right. A declared .d.ts can still be missing for some entry points or disagree with the JavaScript. The guide to shipping types describes tools that check that.
  • Older versions. It checks the latest version only. A project pinned to an older release may need @types even if the latest version ships types, or the other way round.