Search code examples
javascriptnode.jstypescripttsd

Is there an easy way to install TypeScript definitions?


So I have been trying to use TypeScript in the last few days and I am having trouble installing definitions for external modules.

I have no problems if I use tsd like this:

tsd install express

However it seems that tsd is deprecated and I should be using typings.
So I try to run this command:

typings install --ambient express

This is the output:

typings INFO reference Stripped reference "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/serve-static/serve-static.d.ts" during installation from "express"

typings INFO reference Stripped reference "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/express-serve-static-core/express-serve-static-core.d.ts" during installation from "express"

express
└── (No dependencies)

Then I have to manually install the stripped references, and when I do, I still get errors when compiling with tsc but when I use tsd all references are installed and I get no errors during compiling.

I just want to install the definitions as easy as possible.
Is it safe to use tsd or might I run into some problems in the future?

Why doesn't typings install them?
Imagine if you run npm install express and then you get a list of dependencies and you have to recursively install all dependencies.

How much time per module should I spend just to install the definition files?

I can't find an answer online. How do other people handle this?
Also what should I do if there are no definitions available for some module?


Solution

  • As @BrunoLM pointed out in the comment, with the release of TypeScript 2.0, this is the way to install declaration files now:

    npm i @types/express
    

    References: