【问题标题】:Flow (flowtype) and react: defaultProps are not controlled?流(flowtype)和react:defaultProps不受控制?
【发布时间】:2018-03-20 06:20:41
【问题描述】:

使用v0.68.0,好像defaultProps不受控制:

以下代码(来自official doc)在声明“foo”defaultProp(作为字符串而不是数字)时不会引发错误:

// @flow
import * as React from "react";

type Props = {
  foo: number,
};

class MyComponent extends React.Component<Props> {
  static defaultProps = {
    foo: 'bad string',
  };
}

(见TryFlow example)

有什么想法吗? 谢谢

【问题讨论】:

    标签: javascript reactjs react-native flowtype


    【解决方案1】:

    当您尝试创建组件时会检查它们,即:

    <MyComponent />
    

    引发相应的错误,请参阅TryFlow here。正如flow/#3499 中的对话所示,这似乎是设计使然。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-27
      • 2017-06-30
      • 1970-01-01
      • 2016-08-03
      • 2015-09-15
      • 1970-01-01
      • 2018-09-10
      • 1970-01-01
      相关资源
      最近更新 更多