typescript - Eslint 不使用 TypeScript 语法

标签 typescript eslint

我正在尝试配置 eslint我的 REACT-TypeScript项目。它以前使用过 tslint这将很快被弃用。我浏览了网络,终于能够创建我的 .eslintrc.json :

{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "project": "./tsconfig.json",
    "ecmaVersion": 2018,
    "sourceType": "module"
  },
  "env": {
    "browser": true,
    "jest/globals": true
  },
  "extends": [
    "airbnb",
    "plugin:react/recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:import/typescript",
    "prettier/@typescript-eslint",
    "plugin:prettier/recommended"
  ],
  "plugins": ["@typescript-eslint", "react-hooks", "jest", "prettier"],
  "ignorePatterns": ["src/serviceWorker.ts", "src/enums.ts", "node_modules/"],

  "rules": { },
  "settings": {
    "import/extensions": [".js", ".jsx", ".ts", ".tsx"],
    "import/parsers": {
      "@typescript-eslint/parser": [".ts", ".tsx"]
    },
    "import/resolver": {
      "node": {
        "extensions": [".js", ".jsx", ".ts", ".tsx"]
      }
    }
  },
  "prettier/prettier": [
    "error",
    {
      "singleQuote": true,
      "semi": "error"
    }
  ]
}

当我运行 lint命令,它会抛出关于 TypeScript 的错误句法。这里有几个:

enter image description here

enter image description here

谷歌上的所有链接现在都是紫色的,但我似乎无法弄清楚出了什么问题。请帮我看看这个。

最佳答案

对我来说你的配置看起来不错。如果是 Typescript 错误,则 ESLint 无能为力。只需升级 typescript 。

以防万一,请检查此 ESLint Prettier Typescript 引用我的配置https://levelup.gitconnected.com/setting-up-eslint-with-prettier-typescript-and-visual-studio-code-d113bbec9857 ?它离你很近

关于typescript - Eslint 不使用 TypeScript 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59827402/

相关文章:

reactjs - react typescript : FunctionComponent with templated props

html - 使用 Chrome 调试 React TypeScript .tsx 文件 - Webpack

javascript - 如何在 angular 2 中再次调用 ngAfterViewInit 中的代码

javascript - 强制 eslint 在某些文件上导入时使用默认导出模块的原始名称

javascript - Prettier 和 eslint 缩进不一起工作

javascript - 未检测到 ESLint 的 React Prop-Types

typescript - 带有 ES6 的 Webpack Karma + Typescript

typescript - typescript-eslint 未使用 tsconfig

javascript - rc 在配置文件的名称中代表什么?

angular - 如何将两个 firebase 集合组合成一个新的对象数组