`Why does history have type any?
M
M
miliko mikoyan2019-06-18 18:00:34
typescript
miliko mikoyan, 2019-06-18 18:00:34

Why does history have type any?

Why is history of type `History<any>`;

function BasicExample() {
          return (
            <Router>
              <div>
                <Link to="/about/product">About</Link>
                <Route exact path="/about/:product" component={RouteProduct} />
              </div>
            </Router>
          );
        }
        
        const RouteProduct = withRouter(
          ({ match, history }: RouteComponentProps<{ product: string }>) => (
            <Fragment>
             10
            </Fragment>
          )
        );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-06-18
@miliko0022

If you are working through an IDE, then going through the type chain you will see that History is:
and LocationState in turn:
In theory, the type should be overridden by the third argument of RouteComponentProps, but this does not work for me. Perhaps a bug.
Also, the withRouter wrapper is not needed in your example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question