Using TSD for Typescript Definitions

This is an older post published on my blog on Jan 20 2015, I’m moving a few posts over here.

What is TSD?

TSD is a package manager to search and install TypeScript definitions files directly from the community driven DefinitelyTyped repository. While developing in typescript I’ve found it a bit distracting to have to keep going off to find the definitions; this has sped me up a lot.

I’ll be going through this as if you’re in Visual Studio as that’s where I was doing it. It’ll translate fine to the terminal though, just ignore any references to the package management console.

Note: When I was setting this up with version 0.5.7 I didn’t have some of the required commands. I needed to the get the next version which was pre-rekease, I had to run:

I don’t imagine this will be the situation for long though.

Let’s get started

  1. You’ll need to install TSD globally so start of with: npm install tsd -g
  • Repo is going to set where it gets the typings from and ref is the branch. TSD is basically pulling from a github repo.
  1. If you want to query to see if a package is available: tsd query angular
  • -r is resolve, this is going to grab dependencies.
  1. Go check out your tsd.json file. You’ll see your dependencies. Also go have a look at the file you specified for bundle too.
grunt.initConfig({ 
tsd: {
refresh: {
options: {
// execute a command
command: ‘reinstall’,
// optional: always get from HEAD
latest: true,
// specify config file
config: ‘../conf/tsd.json’,
// experimental: options to pass to tsd.API
opts: {
// props from tsd.Options
}
}
}
}
})

You’ll need to install this, I just added “”grunt-tsd”: “~0.2.0”” to my package.json file and let npm grab it. Also add: “grunt.loadNpmTasks(‘grunt-tsd’);” to your gruntfile.js.

That wraps it up, hopefully this saves you some time going back and forth to DefinitelyTyped.