【问题标题】:TypeScript type definitions IntelliSense errorsTypeScript 类型定义 IntelliSense 错误
【发布时间】:2022-01-22 18:23:29
【问题描述】:

使用 Visual Studio 2022,我在错误列表窗口中有很多关于 node_modules 文件夹类型定义的 IntelliSense 错误。
在我的 tsconfig.json 文件中,我排除了 node_modules 文件夹:"exclude": ["node_modules"].
在我的 csproj 中,我添加了 <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> 行。
但是没有任何效果,我没有成功消除这些错误。

【问题讨论】:

  • 你试过重启VS吗?其他 IDE 中也发生了类似的事情,为了处理这种情况,我们需要重新启动 typescript 服务。
  • 我每天早上都会重新启动它:)

标签: typescript visual-studio


【解决方案1】:

经过大量试验和错误,我已经让"exclude": ["./node_modules/**/*.*"] 成功忽略 node_modules。直到我重新启动 Visual Studio 才生效。

【讨论】:

  • 它对我不起作用。我也试过 "skipLibCheck": true 但我总是有这些错误。
  • 我不认为这是一个理想的解决方案,它是一种解决方法。如果您可以与我们分享 tsconfig 和 typescript 版本的详细信息,那么我们都可以为您找到理想的解决方案。默认情况下,exclude 不包括 node_module。你不需要明确定义它。
【解决方案2】:

这取决于你的 tsconfig - 你能分享你的设置吗?会想要排除你的 dist 文件以及你的 node_modules(如果你想要测试/规范文件)。

"exclude": ["node_modules", "**/*.spec.ts", "dist"]

Webpack 没有导出成员编译是我首先看到的错误 - 你在导入什么? Docs here 用于 webpack 和 typescript。

想知道您的类型是否可发现,可以尝试在下面添加到 tsconfig

"typeRoots": [
   "./node_modules/@types"
]

【讨论】:

  • 这是我的 tsconfig.json :{ "compilerOptions": { "noImplicitAny": false, "noEmitOnError": true, "removeComments": true, "sourceMap": true, "target": "es5" }, "compileOnSave": false, "exclude": [ "bin", "node_modules", "wwwroot" ] }
  • 我使用 webpack 编译 typescript 文件,所以我在我的 csproj 中添加了 <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> 行。
猜你喜欢
  • 2016-05-27
  • 2021-08-20
  • 2020-10-18
  • 2015-10-16
  • 1970-01-01
  • 2017-12-21
  • 2019-04-01
  • 2019-05-07
  • 2018-02-24
相关资源
最近更新 更多