Reactjs 反应+;流量+;埃斯林特
我一整天都在想这个错误。我正在尝试将流添加到我的React应用程序中 我有一个组件声明如下:Reactjs 反应+;流量+;埃斯林特,reactjs,eslint,type-safety,Reactjs,Eslint,Type Safety,我一整天都在想这个错误。我正在尝试将流添加到我的React应用程序中 我有一个组件声明如下: // @flow class MyComponent extends Component { static defaultProps = { prop1: 'a', prop2: 'b' }; handleOnClick: (value: string) => void; props: MyComponentProps; } MyComponent支柱的名称和类型
// @flow
class MyComponent extends Component {
static defaultProps = {
prop1: 'a',
prop2: 'b'
};
handleOnClick: (value: string) => void;
props: MyComponentProps;
}
MyComponent支柱的名称和类型
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
和。
我已将flowtype/define flowtype
规则添加到我的.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
}}
我缺少什么?您是否使用从“React”导入React的
导入React?您收到错误的原因是lint无法检测到您的环境
您可以在“.eslintrc.json”文件中进行如下编辑
"env": {
"browser": true,
"es6": true
},
或
},
有关更详细的信息:Yes:)这是一个工作组件,我只是想给它添加类型安全性。props`props:MyComponentProps;`-->这是它不知道在哪里申报的投诉之一。如果这是一个组件,那么您需要使用propTypes或contextTypes。看看这篇文章。请询问是否还有其他问题。处理程序应声明为您试图导出的类中的函数。应该是handleClick(){}
您正在导出的类的末尾也缺少一个分号。我认为您没有抓住要点。我正在尝试向组件添加流,我相信我做的是正确的。我不想要propTypes
。你是在声明中得到了那些ESLint错误,还是在你引用它们的地方?在声明中。你有什么版本的ESLint、babel ESLint和ESLint插件流类型?请详细说明,伙计,不要提供意见作为答案(我想或者我猜,等等)。谢谢你的警告@Rai
"parserOptions": {
"ecmaVersion": 6