Using TSD for Typescript Definitions

What is TSD?

Let’s get started

  1. You’ll need to install TSD globally so start of with: npm install tsd -g
  2. Navigate to your project folder as you would with a command prompt or it’s going to stick these files into you solution root.
  3. Run the following to get the json file that is going to hold your configuration: tsd init
  4. Now we can take a look inside of our empty (ish) tsd.json file:
  • Repo is going to set where it gets the typings from and ref is the branch. TSD is basically pulling from a github repo.
  • Path is where we’re going to output out typings to.
  • Bundle is a nice file created with all of the reference paths added for your typings. This is going to save you adding them to the top of your typescript files like a caveman :P.
  • Installed is going to list our definitions and the commit hash so we always get the same file, we can update them if we need to later.
  1. If you want to query to see if a package is available: tsd query angular
  2. Cool, it’s in there! Lets do a: tsd install angular -r -o -s
  • -r is resolve, this is going to grab dependencies.
  • -o is overwrite, It’ll go over the top of any files already existing.
  • -s is save, this will save the tsd.json file.
  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.
  2. We can also add a grunt step to reinstall from this file:
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




Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ben Gale

Ben Gale

More from Medium

Bundling a TypeScript library for Node with Rollup.JS

JS/TS — add and remove eventlisteners properly without loosing the “this” context

How to mock files with TestDouble, TypeScript and Jest

Summary of high-level built-in types in TypeScript