【发布时间】:2018-09-10 22:12:13
【问题描述】:
经过数小时的搜索和测试,我没有成功找到任何解决方案来让 flow 理解 defaultProps
使用这个模型是不一致的:
type PropsType = {|
size?: 'small' | 'big',
|};
class Letter extends PureComponent<PropsType> {
static defaultProps = {
size: 'small',
}
}
谢谢
编辑
在 Tomasz Mularczyk 的建议下,我创建了another Try Flow example :
type PropsType = {|
size: 'small' | 'big',
|};
而不是
type PropsType = {|
size?: 'small' | 'big',
|};
但是
defaultProp size 不再输入:
static defaultProps = {
size: 'BAD DEFAULT PROPS', // no error (?!)
}
解决方案
查看 Tomasz Mularczyk 的回答
+
不要等待当前组件上的流错误(在我的情况下),而是在哪里导入和声明它。(似乎是半静态的?)
【问题讨论】:
标签: reactjs react-native flowtype