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

问题描述

我正在用React编写TypeScript。该项目由CRA生成。我为import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo',theme: ThemeData( primarySwatch: Colors.blue,visualDensity: VisualDensity.adaptivePlatformDensity,),home: MyHomePage(title: 'Flutter Demo Home Page'),); } } class MyHomePage extends StatefulWidget { MyHomePage({Key key,this.title}) : super(key: key); final String title; @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { int _counter = 0; void _incrementCounter() { setState(() { _counter++; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.title),body: ClipRRect( borderRadius: BorderRadius.only(bottomLeft: Radius.circular(10.0)),child: Container( decoration: BoxDecoration( border: Border( right: BorderSide( color: Colors.red,width: 2,//borderRadius: BorderRadius.only(bottomLeft: Radius.circular(10.0)),color: Colors.grey,child: Column( children: <Widget>[ Padding( padding: EdgeInsets.only(top: 5,bottom: 5),child: Text("......")) ],)),floatingActionButton: FloatingActionButton( onPressed: _incrementCounter,tooltip: 'Increment',child: Icon(Icons.add),); } } 使用了react-app配置。但是我决定使用.eslintrc.json,所以我添加了它并更改了eslint-config-airbnb

.eslintrc.json

突然我从ESLint收到了关于我在代码库中使用的{ "extends": [ "airbnb",] } 类型的解析错误

enum

我用Google搜索了它,但是找不到答案。试图添加一些额外的配置,如

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

但不能解决问题

解决方法

我发现我只需要在ESLint的配置文件中添加这一行

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

在此处查看入门文档,以获取有关如何设置打字稿代码库以使用ESLint进行编码的信息

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...