How does one add a typing to typings.json for Typescript in Visual Studio 2015?
Solution 1
- Make sure you have npm installed
- Open up your console of choice (e.g. command prompt or powershell)
- Navigate to your project folder
Using only npm (TypeScript 2 and later):
-
npm install --save @types/jquery
Done: See this for more info.
Using typings (Typescript before v.2):
- Make sure you have typings installed, if not run
npm install typings --global
-
Write
typings install dt~jquery --save --global
This should update your typings.json file and download the definition files.
In the above example for typings, 'dt~' means that it should look for jquery in the DefinitelyTyped repository, the default is 'npm'. The syntax has changed slightly from version 0.x to 1.0, the flag
--global
was previously--ambient
.
Solution 2
I found that opening and resaving package.json once the typings.json file had been created triggered the typings to pull down. This is my current typings file:
{
"ambientDependencies": {
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd",
"jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd"
}
}
Zachary Scott
#SOreadytohelp Recommended books: Agile Principles, Patterns, and Practices in C# Applying Domain-Driven Design and Patterns Patterns of Enterprise Application Architecture Design Patterns (GOF) Refactoring: Improving the Design of Existing Code Test Driven Development: By Example Implementation Patterns Domain-Driven Design (Evans)
Updated on November 26, 2020Comments
-
Zachary Scott over 3 years
I have to ask because this is driving me crazy. I see the npm way of installing typings on Google, but Angular2's tutorial has one add a typings.json file then it added the typings folder and downloaded d.ts files from DefinitelyTyped automatically. I tried this with jquery but it didn't download. I also tried rebuilding the project, which I would expect the package.json to include the commands to add additional typings.
Here's my scripts from the package.json file:
"scripts": { "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ", "tsc": "tsc", "tsc:w": "tsc -w", "lite": "lite-server", "typings": "typings", "postinstall": "typings install" }
Here's the typings.json file I tried. es6-shim and jasmine downloaded.
{ "ambientDependencies": { "es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd", "jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd", "jquery": "github:DefinitelyTyped/DefinitelyTyped/jquery/jquery.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd" }}
It's probably something simple like not having what appears to be a checksum after the hashtag. Where would I find the correct checksum, or what command do I need to add to package.json to retrieve the typings upon compile, or what am I doing wrong?
Here's another example of adding a line to the typings.json file and then it installs the d.ts files for you. Scroll down until you see Manual Typings