【问题标题】:flow - What kind can I use for the history.push of the react router using Flow for typing?flow - 使用 Flow 进行输入的 react 路由器的 history.push 可以使用哪种类型?
【发布时间】:2018-11-22 15:01:03
【问题描述】:

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

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

登录成功后我使用react路由路由到路由

 history.push("/user");

但是出现如下错误,在flow中没有找到类型

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

【问题讨论】:

    标签: reactjs flowtype


    【解决方案1】:

    看起来您的历史对象类型为string,这就是错误抱怨字符串没有推送属性的原因。历史类型应该是来自流类型定义的RouterHistoryhttps://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

    【讨论】:

      猜你喜欢
      • 2020-07-13
      • 1970-01-01
      • 2022-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多