javascript - 来自 react-redux 的连接的高阶组件不适用于 Typescript Typings
问题描述
我创建了必须通过连接函数连接到 redux 存储的高阶组件。实际上一切都在纯 Javascript 中工作,但我想在这里使用 Typescript。有一个与道具输入有关的错误。
我正在为 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' 的类型不兼容。
解决方案
请在 TypeScript 中观看这个React 和 Redux - 静态类型指南
推荐阅读
- java - 连接到 Solace 时出现 CertificateException
- r - dplyr summarise 然后 summarise_at 在同一个管道中
- discord.py-rewrite - How can I mention whoever was mentioned in the command trigger?
- ios - iOS NSLocale.CurrentLocale.CountryCode 返回语言而不是国家代码
- c - 如何将列数据转换为行数据?
- javascript - 为 JavaScript 'if event.target' 使用类名
- r - 将时间的字符向量转换为 R 中的正确格式和 bin
- typescript - 在 TypeScript 中使用命名空间和 WebPack 时修复类不是构造函数错误
- xamarin - Xamarin 应用程序可以在 BrowserStack 上使用 App Live Local Testing
- wordpress - Woocommerce:检查购物车是否包含任何产品的功能