我有以下JSX。类似的东西:
{
event.divisions &&
event.divisions.edges &&
(event.divisions.edges: Array<Object>)
.map(d => d.node)
.map(division => (
<div>{division}</div>
))
}
没有施法,它告诉我它缺少一个注释。随着铸造我得到以下错误:
81: (event.divisions.edges: Array<Object>)
^^^^^^^^^^^^^^^^^^^^^ property `edges` of unknown type. This type is incompatible with
81: (event.divisions.edges: Array<Object>)
^^^^^^^^^^^^^ array type
这怎么可能不相容?怎么可能不知道呢?我明确告诉它类型。
答案 0 :(得分:0)
您可以按照以下方式映射对象数组
{
event.divisions &&
event.divisions.edges &&
event.divisions.edges.map(d => {
return d.node.map(division => (
<div>{division}</div>
))
}
}
答案 1 :(得分:0)
尝试这样做:
{
event.divisions &&
event.divisions.edges &&
(event.divisions.edges: $ReadOnlyArray<Object>)
.map(d => d.node)
.map(division => (
<div>{division}</div>
))
}