TypeScript Finding definition files


for typescript 2.x:

definitions from DefinitelyTyped are available via @types npm package

npm i --save lodash
npm i --save-dev @types/lodash

but in case if you want use types from other repos then can be used old way:

for typescript 1.x:

Typings is an npm package that can automatically install type definition files into a local project. I recommend that you read the quickstart.

npm install -global typings

Now we have access to the typings cli.

  1. The first step is to search for the package used by the project

    typings search lodash
    NAME              SOURCE HOMEPAGE                                        DESCRIPTION VERSIONS UPDATED
    lodash            dt     http://lodash.com/                                          2        2016-07-20T00:13:09.000Z
    lodash            global                                                             1        2016-07-01T20:51:07.000Z
    lodash            npm    https://www.npmjs.com/package/lodash                        1        2016-07-01T20:51:07.000Z
  2. Then decide which source you should install from. I use dt which stands for DefinitelyTyped a GitHub repo where the community can edit typings, it's also normally the most recently updated.

  3. Install the typings files

     typings install dt~lodash --global --save

Let's break down the last command. We are installing the DefinitelyTyped version of lodash as a global typings file in our project and saving it as a dependency in the typings.json. Now wherever we import lodash, typescript will load the lodash typings file.

  1. If we want to install typings that will be used for development environment only, we can supply the --save-dev flag:

     typings install chai --save-dev