问题
I've seen a lot of threads and discussions about that but I'm not getting to fix the issue. This is my post from some days ago.
One of the purposes of typings
is to avoid the use of <reference>
tags, right?
But if I don't use it, Visual Studio complains:
Visual Studio stops complaining once I reference browser.d.ts
.
Here is my tsconfig
:
{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es5"
},
"files": [
],
"exclude": [
"node_modules",
"wwwroot"
]
}
I also tried removing the "files"
property from the tsconfig
as suggested here, but if I do this, I get compilation error in other typescript files inside the ambient folder of typings.
The code runs and all is fine, but I want to understand if I'm doing something wrong or if it's a Visual Studio problem.
回答1:
For those who might have the same issue in the future:
I fixed the issue. The secret is to exclude the "files"
property from tsconfig
and in the "excluded"
section add the folder "typings"
.
The tsconfig
should now look like that:
{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es5"
},
"exclude": [
"typings",
"node_modules",
"wwwroot"
]
}
回答2:
In my case I fixed adding "jasmine"
into "types"
section in tsconfig.json
. Like this:
{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es5"
},
"exclude": [
"typings",
"node_modules",
"wwwroot"
],
"types": ["jasmine"]
}
来源:https://stackoverflow.com/questions/36080113/typescript-error-cannot-find-name-in-visual-studio