【发布时间】:2019-11-01 02:45:27
【问题描述】:
我创建了高阶组件,必须通过连接函数连接到 redux 存储。实际上一切都在纯 Javascript 中工作,但我想在这里使用 Typescript。 props 输入有一个错误。
我正在为 Wrapped Props 组件使用通用类型,而且我的高阶组件有他自己的 Props 类型。所以我想通过 & 运算符连接它们,但是我从连接函数中得到错误..
WithSatsFormProps为空接口
const withSatsForm =
<P, K>(options: WithSatsFormOptions<K>) =>
(SatsComponent: ComponentType<P>) => {
class WithSatsForm extends Component<WithSatsFormProps & P> { <-- because of this
constructor(props: WithSatsFormProps & P) {
super(props);
}
public render() {
return (
<div>
<SatsComponent {...this.props as P} />
</div>
)
}
}
return connect()(WithSatsForm); <-- here is error typing
}
export default withSatsForm;
错误信息:
“typeof WithSatsForm”类型的参数不能分配给“ComponentType, WithSatsFormProps & P>>”类型的参数。 类型 'typeof WithSatsForm' 不可分配给类型 'ComponentClass, WithSatsFormProps & P>, any>'。 参数“props”和“props”的类型不兼容。
【问题讨论】:
标签: javascript reactjs typescript high-order-component