【问题标题】:React router in TypeScript- both router and own propsTypeScript 中的 React 路由器 - 路由器和自己的 props
【发布时间】:2018-05-18 21:08:09
【问题描述】:

我的组件有一些自己的道具

class Props {
  wizard: WizardConfig;
}

我想访问路由器历史记录,所以我也传递了路由器道具

type PropsType = Props & RouteComponentProps<{}>;

class Wizard extends React.Component<PropsType> {}

问题是在组件的使用中

 <Wizard wizard={someWizar} />

我收到 RouteComponentProps 道具未通过的错误,例如: Property 'match' is missing in type '{ wizard: WizardConfig; }'

我尝试过:

export default withRouter(Wizard);

但它没有帮助。

【问题讨论】:

  • 如果您希望该类型具有 Route... 的一个或多个属性...但不是全部,您可以尝试声明为 Partial - Partial我>

标签: reactjs typescript react-router


【解决方案1】:

固定通过改变

export default withRouter(Wizard);

export default withRouter<PropsType>(Wizard);

【讨论】:

    猜你喜欢
    • 2020-07-27
    • 1970-01-01
    • 2016-07-03
    • 2016-10-26
    • 1970-01-01
    • 2018-03-13
    • 2022-01-21
    • 1970-01-01
    • 2017-08-19
    相关资源
    最近更新 更多