Export single .d.ts from several typescript files + entrypoint
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
intsconfig.json
the compiler will also generate an
entrypoint.d.ts
file (that re-exports thed.ts
of classA and classB)Point the
typings
entry of yourpackage.json
toentrypoint.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.
For anyone who finds this post. You can try npm-dts utility. This should do the trick.
This one worked for me and it was pretty straight forward: https://github.com/TypeStrong/dts-bundle
I tried these without luck:
- https://github.com/Microsoft/dts-gen
- https://github.com/SitePen/dts-generator