Everything about TS 2.x @types
seems so awesome, but I cannot for the life of me figure out how to get it working correctly!
- I have Visual Studio 2015 installed - version
14.0.25431.01 Update 3
- I have TypeScript
2.1.4
for Visual Studio 2015 installed, which I got from here - The VS Web project has been set to use TypeScript 2.1 with
<TypeScriptToolsVersion>2.1</TypeScriptToolsVersion>
Here's a relevant portion from my packages.json
file
"dependencies": {
"angular": "^1.5.9",
"angular-messages": "^1.5.9",
"angular-ui-bootstrap": "^2.3.0",
"angular-ui-router": "^0.3.2",
"moment": "^2.17.0",
"underscore": "^1.8.3"
},
"devDependencies": {
"@types/angular": "^1.5.21",
"@types/angular-ui-bootstrap": "^0.13.36",
"@types/angular-ui-router": "^1.1.35",
"@types/jquery": "^2.0.34",
"@types/node": "^0.0.3",
"@types/signalr": "^2.2.32",
"@types/underscore": "^1.7.36"
}
And here's my full tsconfig.json
file
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"sourceMap": true,
"target": "ES5"
},
"typeAcquisition": {
"enable": true
}
}
I've also tried variations with typeRoots
and types
specified (one, the other, both, neither) inside the compilerOptions
, but no luck!
"typeRoots": [
"./node_modules/@types"
],
"types": [
"angular",
"angular-ui-bootstrap",
"angular-ui-router",
"jquery",
"moment",
"signalr",
"underscore"
]
I've cleaned the build, restarted Visual Studio, etc. but no matter what I do I just get build errors like
some-file.ts(8,22): error TS2304: Build:Cannot find name 'angular'.
some-file.ts(12,41): error TS2694: Build:Namespace 'angular' has no exported member 'IScope'.
some-file.ts(12,67): error TS2694: Build:Namespace 'angular' has no exported member 'IRootElementService'.
another-file.ts(26,22): error TS2503: Build:Cannot find namespace 'moment'.
another-file.ts(47,37): error TS2304: Build:Cannot find name 'moment'.
All of the typedefs exist on disk in either node_modules/@types
or with the relevant package itself. I have no idea why Visual Studio/TypeScript cannot find these files! I feel like something was either not ready to be released yet, or I'm missing something extremely simple. Please someone point me in the right direction here
If you haven't got this resolved yet try uninstalling the typescript tools from uninstall/install programs (you may have multiple versions like I did) and reinstalling the typescript tools @ v2.1.4 via the install package you already have. Double check in visual studio that, that is the version you are using (it should have the details in 'about microsoft visual studio' in the help menu)
Here's my tsconfig in case that helps:
This works for any types that export a module but I have still had issues when importing individual typings when they aren't modules (ie just interfaces etc)...
Generally I haven't had to do any
import * from x
statements for libraries and have been able to just use the name of the module exported directly.