【发布时间】:2017-11-14 09:47:37
【问题描述】:
我整天都在努力解决这个错误。我正在尝试将 Flow 添加到我的 React 应用中。
我有一个这样声明的组件:
// @flow
class MyComponent extends Component {
static defaultProps = {
prop1: 'a',
prop2: 'b'
};
handleOnClick: (value: string) => void;
props: MyComponentProps;
}
然后输入 MyComponentProps
type MyComponentProps = {
prop1: string,
prop2: string
};
现在,Flow 没有报告任何错误。但是当我尝试运行该应用程序时,我收到eslint 错误:
error 'defaultProps' is not defined no-undef
error 'handleOnClick' is not defined no-undef
error 'props' is not defined no-undef
我正在使用babel-eslint 和eslint-plugin-flowtype。
我已将flowtype/define-flow-type 规则添加到我的.eslintrc 文件中。这是我的.eslintrc 文件的相关部分:
{
"parser": "babel-eslint",
"plugins": [
"flowtype",
"react"
],
"extends": [
"plugin:flowtype/recommended"
],
"rules": {
"flowtype/define-flow-type": 1,
"flowtype/use-flow-type" : 1,
"no-undef": 2,
"react/jsx-no-undef": 2
}}
我错过了什么?
【问题讨论】:
-
您是否在声明中或在某处引用了这些 ESLint 错误?
-
关于声明。
-
你有哪些版本的 eslint、babel-eslint 和 eslint-plugin-flowtype?
标签: reactjs eslint type-safety