2017-10-15 31 views
0

看看这个类明白proptypes:流量不

/* @flow */ 
import React, { PureComponent } from 'react'; 
import PropTypes from 'prop-types'; 
import { connect } from 'react-redux'; 

const mapStateToProps = (state) => ({ 
    email: ... 
}); 

@connect(mapStateToProps) 
class UserControlPanel extends PureComponent { 
    static propTypes = { 
     email: PropTypes.string 
    } 
    logout = (ev:any) => { 
     ev.preventDefault(); 

     ... 
    } 
    render() { 
     const { email } = this.props; 

     return (
      <div className="ucp"> 
       ... 
      </div> 
     ); 
    } 
} 

export default UserControlPanel; 

很简单阵营,接受单个字符串支撑命名电子邮件组件类。但是当我运行流量时,它给了我这个错误:

[flow] property email (Property not found in props of React element UserControlPanel See also: React element UserControlPanel)

我是错在哪里?我也试过这样:

type Props = { 
    email: string; 
}; 

@connect(mapStateToProps) 
class UserControlPanel extends PureComponent { 
    props:Props 
    static propTypes = { 
     email: PropTypes.string 
    } 

或者这样:

type Props = { 
    email: string; 
}; 

@connect(mapStateToProps) 
class UserControlPanel extends PureComponent<Props> { 
    static propTypes = { 
     email: PropTypes.string 
    } 

双方将没有奏效。仅使用Component而不是PureComponent也无效。

如何让流程理解我的道具类型并且不再出现错误信息?

回答

1

如果您已经使用流类型验证了您的类型,则不应该使用PropTypes。

相反,请尝试以下操作:

/* @flow */ 
import * as React from 'react'; 
import { connect } from 'react-redux'; 

const mapStateToProps = state => ({ 
    email: ... 
}); 

type Props = { 
    email: string, 
}; 

@connect(mapStateToProps) 
export default class UserControlPanel extends React.PureComponent<Props> { 
    render() { 
     const { email } = this.props; 

     return (
      <div className="ucp"> 
       ... 
      </div> 
     ); 
    } 
} 
+0

那不是一点,但我刚刚更新了我的流程-bin和现在这个工作。谢谢。 – modernator