Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine multiple typescript files into one typescript definition file

Tags:

typescript

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?

like image 266
basarat Avatar asked May 21 '13 00:05

basarat


1 Answers

To create a library you could compile it as follows:

tsc --out 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.

like image 55
Fenton Avatar answered Oct 30 '22 14:10

Fenton