NPM DTS Single File Generator

1.3.13 · active · verified Tue Apr 21

npm-dts is a utility designed to consolidate all TypeScript declaration files (.d.ts) generated for an NPM package into a single index.d.ts file. This enables library developers to distribute bundled JavaScript code while providing comprehensive type definitions, ensuring full type-checking and IDE intellisense for consumers without exposing the original TypeScript source. The current stable version is 1.3.13. While a specific release cadence isn't published, the incremental versioning suggests regular, feature-driven updates. Its primary differentiator is simplifying the distribution of type definitions for compiled libraries, acting as a post-processing step for `tsc` output to create a unified declaration bundle, making library consumption straightforward for TypeScript users. It operates primarily via a command-line interface, requiring `typescript` to be installed in the consuming project's `node_modules`.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to integrate `npm-dts` into a `package.json` script to generate a single `index.d.ts` file after TypeScript compilation for a library project.

// package.json (inside your library project)
{
  "name": "my-library",
  "version": "1.0.0",
  "main": "dist/index.js",
  "types": "dist/index.d.ts", // Point to the generated declaration file
  "devDependencies": {
    "typescript": "^5.0.0", // Required peer dependency for npm-dts
    "npm-dts": "^1.3.0"
  },
  "scripts": {
    "build:ts": "tsc", // Standard TypeScript compilation
    "build:dts": "npm-dts generate --output dist/index.d.ts", // Generate bundled d.ts
    "build": "npm run build:ts && npm run build:dts"
  },
  "files": [
    "dist"
  ]
}

// src/index.ts (example source file)
export function greet(name: string): string {
  return `Hello, ${name}!`
}

export interface User {
  id: number;
  name: string;
}

export class Greeter {
  constructor(private message: string) {}
  sayHello(): string {
    return this.message;
  }
}

// To run this after project setup:
// 1. npm install
// 2. npm run build
// This will compile TS to JS, then bundle all .d.ts files into a single dist/index.d.ts.

view raw JSON →