Definition for rule ‘@typescript-eslint/consistent-type-assertions‘ was not found @typescript-eslin

出现情况:拉下项目后执行npm installnpm start界面出来后报错

报错信息

./src/index.tsx
  Line 1:1:  Definition for rule '@typescript-eslint/consistent-type-assertions' was not found  @typescript-eslint/consistent-type-assertions
  Line 1:1:  Definition for rule '@typescript-eslint/no-unused-expressions' was not found       @typescript-eslint/no-unused-expressions

Search for the keywords to learn more about each error.

解决1:看stackoverflow有人回复到是react-scripts版本问题。如果是这个问题,卸载重装react-scripts。

npm uninstall react-scripts
npm i react-scripts

结果:如果这步ok就不用做第二步了。我这边版本"^4.0.1""^3.1.2"都装过,无效,非react-scripts的原因,转至解决2。

解决2:直接改package.json文件,在eslintConfig下的rules添加off,取消@typescript-eslint/no-unused-expressions校验

  "eslintConfig": {
    "extends": "react-app",
    "rules": {
      "@typescript-eslint/consistent-type-assertions": "off"		//添加这行。
     }
  },

重跑ok。

拓展:ESLint官网对no-unused-expressions的解释

你可能感兴趣的:(报错,ts,前端,node,typescript,bug)