如何对 vscode 中的测试文件使用不同的 tsconfig 文件?

How to use different tsconfig file for test files in vscode?

这个问题类似于这个问题:How to use different tsconfig file for tests? 但是我要求 visual studio 代码。

我有两个 tsconfig 文件:

tsconfig.json 排除所有 *.spec.tstsconfig.test.json 仅包括这些文件。

如何编写 visual studio 代码来理解打开的 .spec.ts 文件属于 tsconfig.test.json

我不想将我所有的测试分成一个自己的 test 目录,其中包含自己的 tsconfig.json,而是将它们放在应用程序文件旁边。

VS Code 目前限制为单个 tsconfig.json(参见:https://github.com/microsoft/vscode/issues/12463)。

考虑到项目结构是:

  • 源/
  • tsconfig.json
  • tsconfig.test.json

创建 ./src/tsconfig.json 文件,内容为:

{
  "extends": "../tsconfig.test.json"
}