typescript - 如何从错误检查中排除非项目目录?

标签 typescript webstorm

我发现我的项目在我的代码之外触发了大量 TypeScript 错误(例如在 <project root>\node_modules\webpack-chain\types\index.d.ts 中)。

我有excluded node_modules<project root>/tsconfig.json :

{
  "extends": "@quasar/app/tsconfig-preset",
  "compilerOptions": {
    "baseUrl": ".",
    "noImplicitAny": false
  },
  "exclude": ["node_modules", "**/*.spec.ts"]
}

我需要通过特殊方式指示 WebStorm 跳过此目录吗?

最佳答案

错误来自 Typescript 编译器服务,而不是来自 IDE。并且编译器 (1) 不应该遵守 IDE 排除过滤器 (2) 不会将 tsconfig.json 中定义的过滤器(默认情况下排除 node_modules)应用于从包含文件引用的文件。 请参阅https://www.typescriptlang.org/tsconfig#exclude :

Important: exclude only changes which files are included as a result of the include setting. A file specified by exclude can still become part of your codebase due to an import statement in your code, a types inclusion, a /// <reference directive, or being specified in the files list.
It is not a mechanism that prevents a file from being included in the codebase - it simply changes what the include setting finds.

因此,如果报告问题的文件包含(通过导入链)到您的任何项目 .ts 文件中,您将看到为其报告的编译器错误

关于typescript - 如何从错误检查中排除非项目目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68512657/

相关文章:

typescript :如何制作一个作为接口(interface)键的类型,但只有作为字符串的键

angular - 页面初始加载时显示两个菜单

dart - 为什么删除我的 web/assets 文件夹也会删除 lib 中的所有源?

intellij-idea - 你如何在 IntelliJ/Webstorm 中移动项目?

node.js - 无法使用 WebStorm 运行 React 应用程序

node.js - 如何读取 csv 文件并将其存储在对象数组中?

javascript - 是否可以一起使用 TypeScript 和 Babel

javascript - typescript 中的 fs/promises api 无法在 javascript 中正确编译

node.js - 在 WebStorm 中将 Node.js 与 Flow 结合使用

javascript - 带有 Webstorm 的 Node.js -