【问题标题】:Disable type checking from all .tsx files禁用所有 .tsx 文件的类型检查
【发布时间】:2020-09-16 06:59:54
【问题描述】:

我正在尝试阻止对我的打字稿项目进行类型检查,因为它仍在开发中。 我尝试在我的 tsconfig 文件中添加"checkJs": false,但仍然键入检查触发器。我找到的唯一解决方案是在我项目的每个文件中添加// @ts-nocheck。有没有一种方法可以禁用类型检查,而不必将// @ts-nocheck 添加到每个文件中,而是在一个地方使用它。

我的tsconfig.json 文件

{
  "compilerOptions": {
    "target": "es5",
    "checkJs": false,
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "noEmit": true,
    "jsx": "preserve",
    "isolatedModules": true
  },
  "include": [
    "src"
  ]
}

【问题讨论】:

  • 我强烈建议您不要关闭类型检查。即使它正在开发中,它也是一个巨大的帮助。你会从一开始就引入很多问题。
  • 我正在处理一个现有的项目,它给出了类型检查错误
  • 所以你要移植一个js项目到ts?然后我建议你保留你的 js 一段时间,为你需要的东西创建定义文件(*.d.ts),并一一移植到 ts。
  • stackoverflow.com/questions/54506744/…这可以回答你的问题

标签: javascript reactjs typescript typechecking tsx


【解决方案1】:

在您的根目录中创建.eslintrc.js 以忽略您想要的内容或配置您的eslint。请阅读docs,里面有很多规则。你的情况:

module.exports = {
  extends: ["react-app", "plugin:prettier/recommended"],
  rules: {
     "@typescript-eslint/ban-ts-ignore": "off"
  },
  plugins: ["react", "@typescript-eslint", "prettier"]
};

忽略类型检查

【讨论】:

    猜你喜欢
    • 2019-06-27
    • 2020-04-21
    • 1970-01-01
    • 2015-06-03
    • 2017-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-22
    相关资源
    最近更新 更多