Package Exports
- dts-bundle-generator
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dts-bundle-generator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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-generatoror
npm install -g dts-bundle-generator- Enable
declarationcompiler options intsconfig.json
Usage
usage: dts-bundle-generator [-h] [-o OUTFILE] [-v] [--no-check] [--output-source-file]
[--fail-on-class] [--external-includes EXTERNALINCLUDES]
[--config CONFIG]
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
--fail-on-class Fail if generated dts contains class declaration
--external-includes EXTERNALINCLUDES
Comma-separated packages from node_modules to include
typings from it
--config CONFIG File path to generator config fileExample:
./node_modules/.bin/dts-bundle-generator -o my.d.ts path/to/your/entry-file.tsTODO
- Add parameter to use custom
tsconfig(currently it uses the closesttsconfig.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:
- There is no one usages of
A(maybe you do not want to export it?) - 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
aorb(actuallyentrytoo).
Known issues
- Currently it does not work with
outDircompiler option.
Known limitations
- 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).
- 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.
- All your types should have different names inside a bundle. If you have 2
interface Options {}they will be merged byTypeScriptand you will get wrong definitions.