# dtsc

> Generate bundled TypeScript declaration files

Latest version **3.1.0** (published 2025-02-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install dtsc
pnpm add dtsc
yarn add dtsc
bun add dtsc
```

Provides the commands `0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`.

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2025-02-24 |
| First published | 2022-05-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 29.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Shigma <shigma10826@gmail.com> |
| Maintainers | shigma |

## Links

- npm: https://www.npmjs.com/package/dtsc
- Repository: https://github.com/shigma/dtsc
- Issues: https://github.com/shigma/dtsc/issues
- npm.io page: https://npm.io/package/dtsc

## Dependencies (1)

- [tsconfig-utils](https://npm.io/package/tsconfig-utils.md) ^4.1.1

## Recent versions

- 3.1.0 (latest) — 2025-02-24
- 3.0.4 — 2024-03-04
- 3.0.3 — 2024-02-08
- 3.0.2 — 2024-02-04
- 3.0.1 — 2024-01-20
- 3.0.0 — 2024-01-20
- 2.3.0 — 2022-11-28
- 2.2.4 — 2022-11-27
- 2.2.3 — 2022-08-25
- 2.2.2 — 2022-08-08
- 2.2.1 — 2022-08-08
- 2.2.0 — 2022-08-08
- 2.1.1 — 2022-07-09
- 2.1.0 — 2022-07-07
- 2.0.0 — 2022-07-06
- … 5 more at https://npm.io/package/dtsc/versions

## README

# dtsc

[![npm](https://img.shields.io/npm/v/dtsc?style=flat-square)](https://www.npmjs.com/package/dtsc)
[![GitHub](https://img.shields.io/github/license/shigma/dtsc?style=flat-square)](https://github.com/shigma/dtsc/blob/master/LICENSE)

Generate bundled TypeScript declaration files.

## Background

TypeScript has a [`outFile`](https://www.typescriptlang.org/tsconfig/#outFile) compiler option:

> If specified, all global (non-module) files will be concatenated into the single output file specified.
>
> If module is system or amd, all module files will also be concatenated into this file after all global content.
>
> Note: outFile cannot be used unless module is None, System, or AMD. **This option cannot be used to bundle CommonJS or ES6 modules.**

Supposing you have a project structure like this:

```
├── src
│   ├── index.ts
│   ├── foo.ts
│   └── bar.ts
├── package.json
└── tsconfig.json
```

After running `tsc --outFile lib/index.d.ts`, the following file will be generated:

```ts
// lib/index.d.ts
declare module "foo" {
  export function someMethod(): void;
}
declare module "bar" {
  export function otherMethod(): void;
}
declare module "index" {
  export * from "foo";
  export * from "bar";
  export * from "baz";
}
```

However, what we really want is:

```ts
// lib/index.d.ts
export function someMethod(): void;
export function otherMethod(): void;
```

This is where dtsc comes in. It generates a single bundled declaration file which behaves like other bundling tools.

## Usage

dtsc supports `outFile` option out of the box.

```jsonc
// tsconfig.json
{
  "compilerOptions": {
    "rootDir": "src",
    "outFile": "lib/index.d.ts",
  },
  "include": [
    "src",
  ],
}
```

```jsonc
// package.json
{
  "typings": "lib/index.d.ts",
  "scripts": {
    "build": "dtsc",
  },
}
```

```bash
npm run build
```

## Limitations

This package uses a string-based approach to generate bundle from a .d.ts file. It may have some limitations:

- If you find one, welcome to report an issue.

<!-- In most cases I would recommend using tsc directly. -->

## See also

- [atsc](https://github.com/shigma/atsc): augment tsc with non-typescript files support

---
_Source: https://npm.io/package/dtsc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
