0Pricing
TypeScript Academy · Lesson

Publishing packages with types

Publish libraries with first-class typings: emit .d.ts with tsc, point package.json to them, handle ESM/CJS exports, and test before publish.

Intro

Goal: Publish a package with solid typings. You will emit .d.ts files, wire package.json correctly, support ESM/CJS via exports, and verify with tsc --noEmit in a sample app.

  • Emit declarations
  • Point types (or per-entry exports)
  • Test before publish

Emit declarations

Enable declaration to emit .d.ts. Use a dedicated build config to keep app tsconfig strict and clean.

// tsconfig.build.json
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "ESNext",
    "declaration": true,
    "emitDeclarationOnly": false,
    "outDir": "dist",
    "rootDir": "src",
    "stripInternal": true
  },
  "include": ["src/**/*"]
}

All lessons in this course

  1. .d.ts basics; export type vs export
  2. Publishing packages with types
← Back to TypeScript Academy