'typeof test'类型的参数不能赋值给'Component&lt; {children?:ReactNode; }&amp; DispatchProp <任何>&GT;”

时间:2017-07-26 09:23:13

标签: reactjs typescript redux react-redux

import * as React from 'react';

import {connect} from 'react-redux';


interface types{

type:string;
status?:boolean;

}


export class Test extends React.Component<undefined,any> {

constructor(props:undefined){
    super(props);
}

private test(){}

render(){
    return(
      <h1 onClick={this.test.bind(this)}>
        test
      </h1>
    )
}

}

export default connect()(Test); 

错误

  

类型'typeof test'的参数不能分配给'Component&lt; {children?:ReactNode; }&amp; DispatchProp&GT;”。   

1 个答案:

答案 0 :(得分:1)

看起来你正在过度工作你的组件;它根本不需要connect来减少,因为它没有使用状态或调度。此外,错误本身指的是props的类型为undefined这一事实,因此未实现连接组件的任何必需属性。

这是简化的组件:

import * as React from 'react';

export default class Test extends React.Component<{}, {}> {
    private test() {}

    render() {
        return(
            <h1 onClick={this.test.bind(this)}>
                test
            </h1>
        );
    }
}