Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dts-bundle-generator

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dts-bundle-generator

DTS Bundle Generator

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
53K
decreased by-7.27%
Maintainers
1
Weekly downloads
 
Created
Source

DTS Bundle Generator

This small tool can generate a bundle of dts 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 it as 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

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

or

npm install -g dts-bundle-generator
  1. Enable declaration compiler options in tsconfig.json

Usage

usage: dts-bundle-generator [-h] -o OUTFILE [-v] [--no-check] [--output-source-file] file

Positional arguments:
  file

Optional arguments:
  -h, --help            Show this help message and exit.
  -o OUTFILE, --out-file OUTFILE
                        File name of generated d.ts
  -v, --verbose         Enable verbose logging
  --no-check            Skip validation of generated d.ts file
  --output-source-file  Add comment with file path the definitions came from

Example:

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

TODO

  1. Add parameter to use custom tsconfig (currently it uses the closest tsconfig.json)

Why?

If you have modules you can create definitions by default via tsc, but it generates them for each module separately. Yeah, you can use outFile (for amd and system) but it generates code 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. There is no one usages of A (maybe you do not want to export it?)
  2. If you bundle your code in such a way all the modules are merged (like when using Webpack or Rollup) and there are no such modules as a or b (actually entry too).

Known issues

  1. Currently it does not work with outDir compiler option.

Known limitations

  1. Do not rename types when import. If you use something like this:
import { A as B } from './b';
export C extends B {}

you will get an error because this tool does not follow your renaming (and actually cannot).

  1. Do not use types from * as name-imports:
import * as someName from './some';
export class A extends someName.SomeClass {}

This case is very similar to the previous one.

  1. All your types should have different names inside a bundle. If you have 2 interface Options {} they will be merged by TypeScript and you will get wrong definitions.

FAQs

Package last updated on 15 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc