TypeScript 错误:在 Visual Studio 中“找不到名称”

问题描述 投票:0回答:2

我已经看到了很多关于此问题的帖子和讨论,但我还没有解决这个问题。 这是我前几天的帖子

typings
的目的之一是避免使用
<reference>
标签,对吧?

但是如果我不使用它,Visual Studio 会抱怨:

一旦我引用

browser.d.ts
,Visual Studio 就会停止抱怨。

这是我的

tsconfig

{
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5"
  },
  "files": [

  ],
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}

我还尝试按照

here
的建议从
"files"
中删除tsconfig属性,但是如果我这样做,我会在typings的环境文件夹内的其他打字稿文件中收到编译错误。

代码运行并且一切正常,但我想了解我是否做错了什么或者是否是 Visual Studio 问题。

visual-studio typescript visual-studio-2015 tsconfig
2个回答
0
投票

对于那些将来可能遇到同样问题的人:

我解决了这个问题。秘诀是从

"files"
中排除
tsconfig
属性,并在
"excluded"
部分添加文件夹
"typings"

tsconfig
现在应该看起来像这样:

{
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5"
  },
  "exclude": [
    "typings",
    "node_modules",
    "wwwroot"
  ]
}

0
投票

就我而言,我修复了将

"jasmine"
添加到
"types"
中的
tsconfig.json
部分。像这样:

{
    "compilerOptions": {
      "noImplicitAny": false,
      "noEmitOnError": true,
      "removeComments": false,
      "sourceMap": true,
      "target": "es5"
    },
    "exclude": [
      "typings",
      "node_modules",
      "wwwroot"
    ],
    "types": ["jasmine"]
}
© www.soinside.com 2019 - 2024. All rights reserved.