react-router-dom with TypeScript

前端 未结 7 578
清歌不尽
清歌不尽 2021-01-30 19:56

I\'m trying to use react router with TypeScript. However, I have certain problems using withRouter function. On the last line, I\'m getting pretty weird error:

A         


        
7条回答
  •  再見小時候
    2021-01-30 20:58

    +1 for Ramon's answer. You can absolutely get full type coverage here. To add a bit - I added the call to withRouter.

    interface FooProps extends RouteComponentProps {
      foo: string;
    }
    
    const Foo = ({ history, foo }: FooProps) => ;
    
    const RoutedFoo = withRouter(Foo);
    

    my dependencies:

    "@types/react-router-dom": "^4.3.0",
    "typescript": "^2.9.2",
    

提交回复
热议问题