Skip to main content

Publishing Type Definitions

It can be useful to be able to publish these types in custom NPM repos e.g. Gitlab

Configuring package.json File

Including src and dist folders

use files key in package.json to indicate which directories should be published (https://stackoverflow.com/questions/67523877/index-d-ts-file-not-published-to-npm). By default you likely want to publish both the source code in src and the compiled/transpiled typescript->js files in dist

e.g.

{
  "files": [
    "dist",
    "src"
  ],
}

Including types and main

You also need to include a types property which tells npm where your defined types (index.d.ts) sits - this is likely to be in dist/index.d.ts if you follow the conventions in this document.

Main module

In a node module you'd probably use src/index.js but we want to use dist/index.js - this will be the compiled version of our typescript module.