【发布时间】:2019-07-15 19:56:42
【问题描述】:
type Color = "Blue" | "Red" | null
type Connect4Cell = {
state: number,
color: Color
}
type State = {
gameBoard?: Array<Array<Connect4Cell>>
}
class Game extends React.Component<{||}, State> {
state = {
gameBoard: [
[{}, {}, {}, {}, {}],
[{}, {}, {}, {}, {}],
[{}, {}, {}, {}, {}],
[{state: 1, color: "Blue"}, {state: 1, color: "Red"}, {state: 1, color: "Blue"}, {state: 1, color: "Red"}, {state: 0, color: null}]
]
}
render() {
let board = this.state.gameBoard.map<React.Element<any>>(row => <Row />)
console.log(this.state)
return (
<div>
<p>This line comes from the render of class, Game. </p>
<table>
<tbody>
{board}
</tbody>
</table>
<Cell />
<Row />
</div>
)
}
}
我不知道为什么它给我这个错误?
确切的错误消息(在 .map 上):
无法调用
this.state.gameBoard.map,因为属性map是 未定义 [1].Flow(InferError) 中缺失
【问题讨论】:
-
顺便说一下,和直接问题无关,但我觉得这个
this.state.gameBoard.map<React.Element<any>>(row => <Row />)应该是简单的this.state.gameBoard.map(row => <Row />)
标签: flowtype