简体   繁体   English

带有 ESLint 的 TypeScript:解析错误:关键字“enum”是保留的 eslint

[英]TypeScript with ESLint: Parsing error: The keyword 'enum' is reserved eslint

I am writing TypeScript with React.我正在用 React 编写 TypeScript。 The project was generated with CRA.该项目是使用 CRA 生成的。 and I used react-app config for the .eslintrc.json .我为.eslintrc.json使用了react-app配置。 However I decided to use eslint-config-airbnb so I added it and changed my .eslintrc.json但是我决定使用eslint-config-airbnb所以我添加它并更改了我的.eslintrc.json

{
  "extends": [
    "airbnb",
  ]
}

suddenly I got parsing error from ESLint about the enum type I used in the codebase突然我从 ESLint 收到关于我在代码库中使用的enum类型的解析错误

`Parsing error: The keyword 'enum' is reserved eslint`

I googled it but cannot find the answer.我用谷歌搜索但找不到答案。 Tried to add some extra config like尝试添加一些额外的配置,例如

"parserOptions": {
    "ecmaVersion": 7,
  }

but it doesn't solve the problem但这并不能解决问题

I found out I just needed to add this one line in the config file of ESLint我发现我只需要在 ESLint 的配置文件中添加这一行

"parser": "@typescript-eslint/parser"

Check out the getting started docs here for information on how to setup your typescript codebase for linting with ESLint在此处查看入门文档以获取有关如何设置 typescript 代码库以使用 ESLint 进行 linting 的信息

https://github.com/typescript-eslint/typescript-eslint/tree/master/docs/getting-started/linting https://github.com/typescript-eslint/typescript-eslint/tree/master/docs/getting-started/linting

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM