Search code examples
reactjsflowtype

flow - What kind can I use for the history.push of the react router using Flow for typing?


What type can I use for the history.push of the react router using Flow for typing?

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

I use the react router to route to the route when the login is done successfully

 history.push("/user");

But the following error appears and I did not find the type in flow

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

Solution

  • It looks like you have the history object typed as a string, which is why the error is complaining about strings not having a push property. The history type should be RouterHistory from the flow-typed definition: 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