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

How to exclude non-project directories from error checking?

我看到我的项目在我的代码之外触发了很多 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 文件中,您将看到针对它报告的编译器错误