RepositoryTypeScript
timocov

timocov/dts-bundle-generator

A tool to generate a single bundle of dts with types tree-shaking

876sao
51fork
13issue
1lượt xem

Thành tựu nổi bật

Những danh hiệu mới nhất của dự án

1
TINIX TRENDING·Chủ đề: definition

#1 Repository của tuần

1
TINIX TRENDING·Chủ đề: dts

#1 Repository của tuần

1
TINIX TRENDING·Chủ đề: typescript-definitions

#1 Repository của tuần

DTS Bundle Generator

GH Actions npm version Downloads

Small tool to generate a dts bundle from your ts code.

For example:

// a.ts
export class A {}
// b.ts
export class B {}
// entry.ts
import { A } from './a';
import { B } from './b';

declare function makeA(): A;
export function makeB(): B {
    makeA();
    return new B();
}

When you run dts-bundle-generator -o my.d.ts entry.ts in my.d.ts you will get the following:

declare class B {
}
export declare function makeB(): B;

Installation

  1. Install the package from npm:

    npm install --save-dev dts-bundle-generator
    

    or

    npm install -g dts-bundle-generator
    
  2. Enable declaration compiler option in tsconfig.json

Usage

Usage: dts-bundle-generator [options] <file(s)>

Options:
  --help                         Show help                                                 [boolean]
  --out-file, -o                 File name of generated d.ts                                [string]
  --verbose                      Enable verbose logging                   [boolean] [default: false]
  --silent                       Disable any logging except errors        [boolean] [default: false]
  --no-check                     Skip validation of generated d.ts file   [boolean] [default: false]
  --fail-on-class                Fail if generated dts contains class declaration
                                                                          [boolean] [default: false]
  --external-inlines             Array of package names from node_modules to inline typings from.
                                 Used types will be inlined into the output file             [array]
  --external-imports             Array of package names from node_modules to import typings from.
                                 Used types will be imported using "import { First, Second } from
                                 'library-name';".
                                 By default all libraries will be imported (except inlined libraries
                                 and libraries from @types)                                  [array]
  --external-types               Array of package names from @types to import typings from via the
                                 triple-slash reference directive.
                                 By default all packages are allowed and will be used according to
                                 their usages                                                [array]
  --umd-module-name              Name of the UMD module. If specified then `export as namespace
                                 ModuleName;` will be emitted                               [string]
  --project                      Path to the tsconfig.json file that will be used for the
                                 compilation                                                [string]
  --check-project                Path to the tsconfig.json file that will be used for the validation
                                 of generated d.ts files (the --project value is used by default)
                                                                                            [string]
  --sort                         Sort output nodes                        [boolean] [default: false]
  --inline-declare-global        Enables inlining of `declare global` statements contained in files
                                 which should be inlined (all local files and packages from
                                 `--external-inlines`)                    [boolean] [default: false]
  --inline-declare-externals     Enables inlining of `declare module` statements of the global
                                 modules (e.g. `declare module 'external-module' {}`, but NOT
                                 `declare module './internal-module' {}`) contained in files which
                                 should be inlined (all local files and packages from inlined
                                 libraries)                               [boolean] [default: false]
  --disable-symlinks-following   (EXPERIMENTAL) Disables resolving of symlinks to the original path.
                                 See https://github.com/timocov/dts-bundle-generator/issues/39 for
                                 more information                         [boolean] [default: false]
  --respect-preserve-const-enum  Enables stripping the `const` keyword from every direct-exported
                                 (or re-exported) from entry file `const enum`. See
                                 https://github.com/timocov/dts-bundle-generator/issues/110 for more
                                 information                              [boolean] [default: false]
  --export-referenced-types      Marks all interfaces, types and const enums as exported even if they
                                 aren't exported directly. By default a node is exported only if it
                                 is exported from the root source file. Fails if a referenced type
                                 cannot be exported because it was renamed due to name collisions.
                                                                          [boolean] [default: false]
  --config                       File path to the generator config file                     [string]
  --no-banner                    Allows remove "Generated by dts-bundle-generator" comment from the
                                 output                                   [boolean] [default: false]
  --version                      Show version number                                       [boolean]

Examples

To generate a dts bundle for a single entry file:

./node_modules/.bin/dts-bundle-generator -o my.d.ts path/to/your/entry-file.ts

To generate a dts bundle for multiple entry files:

./node_modules/.bin/dts-bundle-generator path/to/your/entry-file.ts path/to/your/entry-file-2.ts

To generate a dts bundle for a single entry file with external inlines and imports:

./node_modules/.bin/dts-bundle-generator \
  --external-inlines=@mycompany/internal-project \
  --external-imports=@angular/core rxjs \
  -- path/to/your/entry-file.ts

[!NOTE] Note that, as in the above example, the arguments accepting arrays (like --external-inlines or --external-imports) accept multiple values separated by spaces. Since the input file(s) are positional arguments, you need to put the -- separator before it when it is preceded by an argument that accepts multiple values. Otherwise you will get an error (Error: No input files specified).

To generate a dts bundle for a single entry file with external types:

./node_modules/.bin/dts-bundle-generator --external-types=jquery path/to/your/entry-file.ts

Config file

It is unnecessary, but you can use config file for the tool. See config documentation for more information.

Why

If you have modules then you can create definitions by default using tsc, but tsc generates them for each module separately. Yeah, you can use outFile (for amd and system), but generated code looks like this:

declare module "a" {
    export class A {
    }
}
declare module "b" {
    export class B {
    }
}
declare module "entry" {
    import { B } from "b";
    export function makeB(): B;
}

but:

  1. A is not used at all and most probably you do not want to export it.
  2. If you bundle your code in a way when all modules are merged (like when using Webpack or Rollup) then there should be no such modules as a or b (actually entry too) in the resulting file.

Dự án tương tự

Khám phá các dự án và mô hình AI khác có sự tương đồng.

RepositoryTypeScript
DefinitelyTyped/DefinitelyTyped

The repository for high quality TypeScript type definitions.

51.5k
Nov 27, 2026
RepositoryTypeScript
typed-mxgraph/typed-mxgraph

mxGraph typescript declarations

66
Jan 21, 2025
RepositoryTypeScript
n8n-io/n8n

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

212.9k
Dec 2, 2026
RepositoryTypeScript
microsoft/vscode

Visual Studio Code

195.9k
Nov 30, 2026
RepositoryTypeScript
angular/angular

Deliver web apps with confidence 🚀

101.7k
Dec 1, 2026
RepositoryTypeScript
ant-design/ant-design

An enterprise-class UI design language and React UI library

100.5k
Dec 2, 2026
RepositoryTypeScript
heygen-com/hyperframes

Open-source AI video editor: edit your own footage, or create and remake any video with Claude Code, Codex or the free Studio app. Write HTML, render MP4. By HeyGen.

94.6k
Dec 2, 2026
RepositoryTypeScript
mermaid-js/mermaid

Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown

91.3k
Nov 29, 2026
RepositoryTypeScript
nestjs/nest

A progressive TypeScript framework for Node.js backends: from a small API in one file to efficient, scalable, enterprise-grade systems 🚀

77.2k
Nov 30, 2026