I am having trouble with TypeScript intellisense in Visual Studio 2015. The problem began when I attempted to switch from typings on Nuget to installing them using npm. I have everything I need in node_modules/@types
but intellisense does not find the typings, saying that it cannot resolve the module. The project builds without errors, both using Visual Studio's build and tsc from a command line.
My current guess is that the issue lies in the version of TypeScript I'm using versus the version the typings are for as there are intellisense errors in the typings files when I open them up. For example, I have installed typings(v. ^15.0.21) for React(v. ^15.4.2) using npm. When I open the installed index.d.ts file, I receive numerous errors:
// Type definitions for React v15.0
// Project: http://facebook.github.io/react/
// Definitions by: ...
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
export = React;
export as namespace React;
In these first two lines for example I get:
Cannot compile modules unless the '--module' flag is provided... (entire first line)
Declaration or statement expected. (second line, under export)
You get the idea, these continue through the file. I have tried the following to resolve the issue:
///<reference />
tag pointing to the typings files. Doing this successfully resolves tsx html elements, such as <div>
tags to the JSX.IntrinsicElements
type but the React module still does not resolve, likely because of the errors listed above.typeroots
element in the tsconfig to point directly to the @types folder. I have since removed this at the recommendation of a colleague, one of the two whose intellisense worked.Here is my tsconfig.json file:
{
"compileOnSave": true,
"compilerOptions": {
"sourceMap": true,
"noImplicitAny": false,
"module": "commonjs",
"target": "es5",
"jsx": "react"
},
"exclude": [ "./__Redesign/node_modules", "./__Redesign/jspm_packages" ],
"include": [
"./__Redesign/node_modules/@types",
"__Redesign/app/**/*.ts",
"__Redesign/app/**/*.tsx"
]
}
My tsconfig is in the site root and the package.json
file is in a folder called __Redesign
along with the node_modules
folder. This is why I thought I might need to point the compiler to the typings explicitly in the tsconfig.
At this point I'm running out of leads to chase down and any new ideas are appreciated. Thanks.
After a little more experimenting I tried running a repair on the TypeScript 2.2.2 installer I downloaded earlier and this fixed the problem. I'm not sure what it did to fix the problem, but at least it's working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With