Archived post: posted sometime between 2016 and 2022.

Add TypeScript Definition Files to the NPM Types Organization

I accepted the task to publish the oidc-client-js type definition file to the @types organization on NPM . There are two bits to this task:

  1. Publish the type definitions to NPM.
  2. Update those type definitions easily.

The TypeScript handbook describes two ways to publish declaration files . The handbook recommends the first approach.

There are two main ways you can publish... 1. bundling with your npm package [emphasis added], or 2. publishing to the @types organization on npm. If you control the npm package you are publishing declarations for, then the first approach is favored [emphasis added].

First, we add a main and a types property to our package.json.

{
    "name": "oidc-client",
    "main": "./lib/oidc-client.js",
    "types": "./lib/oidc-client.d.ts"
}

Second, we publicize our type declaration by adding a reference to our package in the DefinitelyTyped repo external package list . Actually, do NOT publicize your declaration files.

The type definitions are now published to NPM, and it's easy to update them.

Note : see the TypeScript handbook for details on including declarations for package dependencies .