我发现我的项目在我的代码之外触发了大量 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/