How to install all typescript definition file based on packages.json?

4k views Asked by At

In my project, I have a package.json file, and use npm install to install all dependencies.
And now, I want auto install all typescript definition file base on package.json.
How can I do it.
Thanks.

1

There are 1 answers

4
Igor On

You can't do it directly, you need to include a tsd.json file which has the references to which typescript definition files you want to use. There are various commands to automatically get everything from your tsd file (including ways to do it via Grunt/Gulp if you want to automate everything).


There might be an option to build up your tsd.json file though. See the documentation, Link to bundled definitions.

Link to bundled definitions

TSD supports discovery and linking of definitions from packages installed with node or bower.

Use the link command and your tsd.d.ts will be updated with paths to the files in the node_modules or bower_modules folders.

$ tsd link

This feature will scan package.json and bower.json files for a typescript element. This element then contains definition or definitions sub-element that contain relative path(s) to .d.ts files:


Again, their documentation is fairly good with good examples everywhere. Check it out let let us know if something is missing or you have a specific problem trying to do something.


Edit - Typings

As mentioned by @JoeClay (see comments below) TSD has been depreciated, use Typings instead. There is a good section on there on converting from TSD to Typings if you have already embedded TSD in your app, otherwise I would recommend you skip TSD and use Typings from the get-go.

As to your original question it still looks like you need a typings.json file which contains references to your typescript (.d.ts) dependencies.