首页 > 解决方案 > 我的项目有 tsx 和 ts 文件,但我想在测试文件中禁用 ts

问题描述

我想在我的测试文件中禁用 TS。测试文件扩展名为 .test.tsx。我尝试禁用 TS 检查,但尽管有下面的代码,TS 仍然抱怨。

"exclude": ["**/*.test.tsx", "**/*.test.ts"]

有谁知道如何在 test.tsx 中成功禁用 TS?在我不想被 TS 检查的文件上使用 .tsx 扩展名是错误的吗?

当我将扩展名更改为 .js 时,一切都按预期工作,但是当所有其他文件都与 ts 相关时突然引入 .js 很奇怪。

tsconfi.gjson

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "types": [
      "node",
      "@testing-library/jest-dom",
    ]
  },
  "include": ["src"],
  "exclude": ["**/*.test.tsx", "**/*.test.ts"]
}

标签: typescripttestingjestjs

解决方案


推荐阅读