Publishing declaration files

suggest change

Libraries written in TypeScript can emit declarations alongside JavaScript:

{
  "compilerOptions": {
    "declaration": true,
    "declarationMap": true,
    "emitDeclarationOnly": false,
    "outDir": "dist"
  }
}

Point package.json at the public entry points and include generated declarations in the published package. This example describes a package that publishes one ESM entry point:

{
  "type": "module",
  "types": "./dist/index.d.ts",
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "import": "./dist/index.js"
    }
  },
  "files": ["dist"]
}

Export only supported public types. Avoid exposing internal paths that consumers cannot import at runtime. Packages that publish both ESM and CommonJS need separate runtime outputs and matching declaration entry points; do not point both conditions at incompatible files. If public declarations reference types from another package, consumers must be able to install and resolve that dependency.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents