react-router-dom with TypeScript

前端 未结 7 576
清歌不尽
清歌不尽 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:44

    This is a Typescript typings issue. Since withRouter() will provide the routing props you need at runtime, you want to tell consumers that they only need to specify the other props. In this case, you could just use a plain ComponentClass:

    export default withRouter(connectModule) as React.ComponentClass<{}>;
    

    Or, if you had other props (defined in an interface called OwnProps) you wanted to pass in, you could do this:

    export default withRouter(connectModule) as React.ComponentClass;
    

    There is slightly more discussion here

提交回复
热议问题