解析错误:“导入类型”中需要“=”

Jer*_*L30 15 eslint create-react-app typescript-eslint

我正在create-react-app与 TS 一起使用,import type但 eslint 在 VS Code 中抱怨说,Parsing error: '=' expected当悬停typeimport type. 我正在使用 eslint,6.7.2

gol*_*pot 13

更新:@typescript-eslint/parser 和@typescript-eslint/eslint-plugin 的最新版本现在支持该语法。


ESLint 对 TSimport type语法的支持正在进行中。

问题:https : //github.com/typescript-eslint/typescript-eslint/issues/1436

拉取请求:https : //github.com/typescript-eslint/typescript-eslint/pull/1465

  • 即使更新到 @typescript-eslint/parser@latest @typescript-eslint/eslint-plugin@latest 之后,我今天也看到了同样的问题 (2认同)

Ali*_*ome 7

更漂亮

如果您使用的是 prettier 而不是 ESLint,那么解决方案是:

npm update prettier@latest
# Or yarn
yarn upgrade prettier@latest

Run Code Online (Sandbox Code Playgroud)

其中安装了更漂亮的版本“2.6.2”。import type { } from './types'这对我的语法有用