Reputation: 1340
I've tried to remove typings from my web project (Visual Studio 2015 Community) and install d.ts files via new NPM @types (typescript 2.0.3) in package.json:
"dependencies": {
"@types/angular": "^1.5.8",
"@types/angular-cookies": "^1.4.2",
"@types/angular-local-storage": "^0.1.33",
"@types/angular-material": "^1.1.37",
"@types/angular-translate": "^2.4.33",
"@types/lodash": "^4.14.36"
}
Visual Studio's IntelliSense worked nicely with typings before because I included typings folder in my VS project. NPM installs types into node_modules/@types
folder. Now here is my problem. I don't really want to include anything from node_modules
in VS project.
node_modules
folder should be fine to get deleted and recreated again by npm at will.
Visual Studio does not recognize the typings installed without them being included in the project!
I guess I could create a file with ///reference tags in it but then I would have to maintain this file manually when installing/removing typings.
Is there any recommended way to make VS IntelliSense work?
Upvotes: 18
Views: 8397
Reputation: 691
Here is an example of using @types in Visual Studio 2015 (as of Update 3)...
First, be sure to have TypeScript v2.0.3 or higher.
Then, add typings as follows:
"devDependencies": {
"typescript": "^2.0.3",
"@types/jquery": "*",
"@types/lodash": "^4.14.36"
}
Then, in your TypeScript file, simply add the following...
/// <reference path="jquery.d.ts"/>
/// <reference path="jquery.lodash.d.ts" />
In order to see if a library type is available, check out Type Search, powered by Definitely Typed.
References:
Upvotes: 1
Reputation: 31
Install VS 2015 Update 3, then install TypeScript 2.0.3 tools.
Upvotes: 2
Reputation: 1228
I was struggling with this same problem after making the switch to 2.0 and using the new @types convention.
I found this useful property after looking into the spec for the tsconfig.json here: http://json.schemastore.org/tsconfig
"typeRoots" property of compilerOptions.
I could not get the files or include arrays to pull in my typings, but this seems to have done the trick for me.
My tsconfig.json file as an example:
{
"compileOnSave": true,
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": false,
"module": "commonjs",
"target": "es5",
"jsx": "react",
"typeRoots": [
"node_modules/@types"
]
}
}
Hope this helps someone with the same issue.
Upvotes: 14