如何在 vscode 中为测试文件使用不同的 tsconfig 文件? [英] How to use different tsconfig file for test files in vscode?

查看:38
本文介绍了如何在 vscode 中为测试文件使用不同的 tsconfig 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题类似于这个问题:如何使用不同的tsconfig用于测试的文件?但我要的是 Visual Studio 代码.

This question is similar to this question: How to use different tsconfig file for tests? But I am asking for visual studio code.

我有两个 tsconfig 文件:

  • tsconfig.json 适用于所有应用程序文件
  • tsconfig.test.json 用于所有测试文件
  • tsconfig.json for all application files
  • tsconfig.test.json for all test files

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

tsconfig.json excludes all *.spec.ts while tsconfig.test.json only includes these files.

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

How can I make visual studio code to understand that an opened .spec.ts file belongs to tsconfig.test.json?

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

I dont want to separate all my tests into an own test directory with its own tsconfig.json included but rather keep them next to the application files.

推荐答案

VS Code 目前仅限于单个 tsconfig.json(请参阅:https://github.com/microsoft/vscode/issues/12463).

VS Code has limitation to a single tsconfig.json for now (see: https://github.com/microsoft/vscode/issues/12463).

考虑到项目结构是:

  • src/
  • tsconfig.json
  • tsconfig.test.json

创建带有内容的 ./src/tsconfig.json 文件:

Create ./src/tsconfig.json file with content:

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

这篇关于如何在 vscode 中为测试文件使用不同的 tsconfig 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆