简体   繁体   English

具有来自react-redux的连接的高阶组件不适用于Typescript Typings

[英]High Order Component with connect from react-redux is not working with Typescript Typings

I've created High Order Component which MUST be connected to redux store, by connect function. 我已经创建了高阶组件,它必须通过连接功能连接到redux存储。 Actually everything is working in plain Javascript, but i would like to use Typescript here. 实际上一切都在普通的Javascript中工作,但我想在这里使用Typescript。 There is one error related to props typing. 有一个与道具打字有关的错误。

I am using Generic Type for Wrapped Props Component and also my High Order Component has his own Props Type. 我使用Generic Type for Wrapped Props Component,我的High Order Component也有自己的Props Type。 So i want to connect them by & operator, but i am getting error from connect function.. 所以我想用运算符连接它们,但我从连接函数得到错误..

WithSatsFormProps is empty interface 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;

Error message: 错误信息:

Argument of type 'typeof WithSatsForm' is not assignable to parameter of type 'ComponentType, WithSatsFormProps & P>>'. 类型'typeof WithSatsForm'的参数不能分配给'ComponentType,WithSatsFormProps&P >>'类型的参数。 Type 'typeof WithSatsForm' is not assignable to type 'ComponentClass, WithSatsFormProps & P>, any>'. 类型'typeof WithSatsForm'不能分配给'ComponentClass,WithSatsFormProps&P>,任何>'。 Types of parameters 'props' and 'props' are incompatible. 参数'props'和'props'的类型是不兼容的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM