1. 提示信息
when use withRouter in your component under the typescript language,it may cause error below
TS12345: Argument of type 'typeof BILink' is not assignable to parameter of type
'ComponentType<RouterComponentProps<any, StaticContext>>'.
Type 'typeof BILink' provides no match for singnature
'{props: RouteComponentProps<any, StaticContext} & {children?: ReactNode;}, context?: any): ReactElement<any>'
2 解决方案
interface props {
// your props here
}
interface states {
// attributes needed in your component here
}
export class YourComponent extends React.Component<props, states>{
// constructor in required here
contructor (props: any){
super(props);
...
}
}
export default withRouter(YourComponent)
another way to solve the problem
type PathParamsType {
// type whatever you expect in the this.props.match.params.*
}
type PropsType = RouteComponentProps<PathParamsType> & {
// your props here
}
export class YourComponent extends React.Component<PropsType>{
...
}
export default withRouter(YourComponent)