Installing Type Definitions

Next, we're going to want to install the type definitions that we'll need for our project. Type definitions are utilized by TypeScript to give the TypeScript compiler more information about a certain codebase. Think for instance if you re using angular in your project, wouldn't it be nice if you could get some intellisense and additonal information about the structure of the codebase?

With type definitions we are able to do just that. Through open source, developers have amassed a large collection of type definitions for just about any JavaScript library/framework or project that you could think of. There are all hosted here on this DefinitelyTyped repository.

The only thing is, manually downloading these things is not fun. You constantly have library authors updating their library which may break the type definitions. So then the type definitions have to get updated and then you have to manually go and check if they updated, yada yada yada.

Wouldn't it be nicer if there was a way to automate this? Well, luckily for us there is! DefinitelyTyped provides a manager to do this work for us, it's called tsd. We installed it earlier through npm.

Let's use it to install the angular dependencies we'll need for this project.

$ tsd install angular --save

You should now see a tsd.json file and a typings/ folder in your project. Under the typings/ folder you should see angular and jquery and a tsd.d.ts file. You may or may not want to add the typings folder to your source control. I typically do, but it's not required. If you just add the tsd.json file it should be enough. When a developer clones this repository all they will have to run is

$ tsd reinstall

and it should re-install the typings folder for them.

Let's add and commit these changes:

$ git add tsd.json typings/tsd.d.ts
$ git commit -m 'add typescript dependencies'

Great! Let's move on to see how using a tsconfig.json file can be a huge win for our TypeScript workflow.