basarat
basarat

Reputation: 276199

Combine multiple typescript files into one typescript definition file

I need this for distributing libraries in TypeScript in a single file. Is there a way to merge multiple typescript files into (one js file + one typescript definition) file?

Upvotes: 13

Views: 10652

Answers (2)

Manfred Wippel
Manfred Wippel

Reputation: 2066

Just in case anyone is searching some solution to combine typescript modules into one single d.ts file https://github.com/timocov/dts-bundle-generator dts-bundle-generator worked for me. Other libraries like npm-dts or dts-bundle are outdated.

Upvotes: 1

Fenton
Fenton

Reputation: 250822

To create a library you could compile it as follows:

tsc --outfile mylib.js --declaration app.ts

This means you get the compiled JavaScript and a TypeScript definition file, and it is still just as simple to use in TypeScript as if it was a single TypeScript file.

You don't need to specify all the files you want to combine, the compiler will walk all the dependencies and bring them all into one file in the correct order. In the example above I have specified only app.ts, but all of the references will be walked and they will all make it into the combined mylib.js and the associated mylib.d.ts files.

Upvotes: 9

Related Questions