javascript - 在对象上设置默认值时,Flow 缺少 Prop 验证

标签 javascript eslint flowtype static-typing

我有一个 React Functional 组件,它将 List 作为 props。

const Dashboard = (props: { items: List } = { items: List() }) => {
  const { items } = props
  ...
})

但是,const { items } = props 中的 items 会产生以下错误:

props validation react/prop-types 中缺少错误“items”

FlowType docs举个例子:

ES2015 features Default values assigned to parameters must come after the parameter’s type annotation:

function foo (P1: T1 = V): U { .. }

但我不太清楚这如何应用于对象

最佳答案

这实际上不是流程错误,而是这个 eslint 错误:

https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md

如果您现在使用流而不关心 proptype,则可以通过禁用 eslint 规则来解决错误。

或者你添加一个 proptype,它没有流那么具体,但是运行时。

Dashboard.propTypes = {
  items: React.PropTypes.object
};

关于javascript - 在对象上设置默认值时,Flow 缺少 Prop 验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42644007/

相关文章:

javascript - 带动画的 Angular 显示/隐藏

javascript - 如何编写 eslint 时尚模式的配置文件?

javascript - 流: Object type incompatible with Array<mixed>

javascript - 如何修改fb :request-form dynamically using Javascript?的内容

javascript - 将二维数组切片为更小的 'blocks' 或 'chunks' 数组

javascript - Radeditor set_html 工作但抛出一个 javascript 错误停止该功能的其余部分

javascript - Eslint 不尊重 jsconfig 路径

javascript - 错误 'NODE_ENV' 未定义 no-undef eslint

javascript - React Flowtype Node.contains() 事件目标

javascript - 如何在flowjs中指定一个可以未定义的参数