typescript && withRouter 错误提示

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)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,490评论 0 10
  • The Inner Game of Tennis W Timothy Gallwey Jonathan Cape ...
    网事_79a3阅读 12,422评论 3 20
  • 从得知自己怀孕那天开始,我就有些担心这个意外的二胎会不会给我带来什么“惊喜”。 正值第9周,嗅觉领先其他官感成为身...
    艾盈升阅读 259评论 1 1
  • 想写下这个问题很久了。 家里有两个孩子,我有个妹妹,小一岁多,所以一直是打打闹闹成长的。她成绩不好,上了个不好的初...
    天哪wency阅读 447评论 0 1