【发布时间】:2020-06-18 04:34:48
【问题描述】:
任何出现的as 运算符都会使[eslint] [E] Parsing error: Unexpected token, expected ";" 指向as 的位置。示例代码:
{error && <small className="invalid-feedback">{(error as any).message}</small>}
这种转换为any 是针对react-hooks-form 的useFormContext 函数中的一些错误的解决方法。
当我忽略错误并编译应用程序时,它工作正常。
这发生在使用最新 TypeScript 和 react-scripts 的标准未弹出 Create React App 中:
$ npm list -dev -depth 0
frontend@0.1.0
├── eslint-plugin-flowtype@3.13.0
├── react-hot-loader@4.12.19
├── react-scripts@3.4.0
└── typescript@3.8.2
AFAIK 除了自动生成的tsconfig.json之外没有配置文件:
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": [
"src"
]
}
任何想法为什么会发生这种情况?
【问题讨论】:
标签: reactjs typescript eslint