【问题标题】:How to disable ALL type checking in *.test.* files (including imported components)如何禁用 *.test.* 文件(包括导入的组件)中的所有类型检查
【发布时间】:2020-04-21 17:23:49
【问题描述】:
tsconfig 中的

"exclude": ["*.test.ts", "*.test.tsx"] 仅阻止对测试特定类型(例如 describe、it、expect 等)的类型检查。我仍然在 vscode 的每个测试文件中看到导入组件的错误。禁用这些导入组件错误的唯一方法是在每个测试文件的开头使用//@ts-nocheck

有没有办法禁用 tsconfig 中所有测试文件的所有类型检查,包括从非测试文件中导入的任何组件?

完整的tsconfig.json 文件(创建 React App 项目)

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "noImplicitAny": false,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react"
  },
  "include": ["src"],
  "exclude": ["*.test.ts", "*.test.tsx"]
}

【问题讨论】:

  • 嗨,你找到解决办法了吗?
  • 您找到解决方案了吗???
  • 请看我的主要答案@Darvesh
  • 请看我的主要答案@DariusV

标签: reactjs typescript create-react-app


【解决方案1】:

我最终选择了另一个问题中列出的按文件禁用选项

How can I disable all typescript type checking?

如果您的测试都在 1 个文件夹中,您可以尝试排除该文件夹,或者禁用该线程中也列出的 .js 文件扩展名。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-30
    • 1970-01-01
    • 2017-07-08
    • 1970-01-01
    • 2019-06-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多