Reputation: 27623
I've several .ts files + 1 entrypoint like so:
entrypoint.ts
contains something similar to:
export * from './classA';
export * from './classB';
I'd like to have a single .d.ts describing everything entrypoint exports so that both ClassA
and ClassB
definition files are included.
Upvotes: 22
Views: 22904
Reputation: 2066
Update for 2024: dts-bundle and npm-dts seem to be outdated
This one is alive and worked for me: https://github.com/timocov/dts-bundle-generator
Generate bundle.d.ts form .ts directly you sometimes need to fix Typescript errors first. like importing global declarations and outdated properties.
Upvotes: 1
Reputation: 29824
You cannot auto-generate a single d.ts
file. What works fine is the following (assuming you are building a library / reusable module):
have the compiler auto-generate declarations for your classes by specifying "declaration": true
in tsconfig.json
the compiler will also generate an entrypoint.d.ts
file (that re-exports the d.ts
of classA and classB)
Point the typings
entry of your package.json
to entrypoint.d.ts
e.g. "typings": "./dist/entrypoint.d.ts"
Assuming your library is called library
, you can now install it in the node_modules
of a project and use it with a standard import:
import {classA, classB} from 'library'
will import the generated d.ts.
for those classes.
Upvotes: 13
Reputation: 199
For anyone who finds this post. You can try npm-dts utility. This should do the trick.
Upvotes: 3
Reputation: 7035
This one worked for me and it was pretty straight forward: https://github.com/TypeStrong/dts-bundle
I tried these without luck:
Upvotes: 2