flow-我可以使用什么类型的历史.使用flow进行输入的react路由器的推送



使用Flow进行输入时,react路由器的history.push可以使用什么类型?

type State = {
...
history: string,
}

当登录成功完成时,我使用react路由器路由到路由

history.push("/user");

但是下面的错误出现了,我没有在流中找到类型

Cannot call `history.push` because property `push` is missing in `String` [1]. (References: [1])

看起来历史对象类型为string,这就是为什么错误抱怨字符串没有push属性的原因。历史记录类型应为流类型定义中的RouterHistory:https://github.com/flow-typed/flow-typed/blob/master/definitions/npm/react-router-dom_v4.x.x/flow_v0.63.x-/react-router-dom_v4.x.x.js#L57

最新更新