【问题标题】:Argument of type 'typeof test' is not assignable to parameter of type 'Component<{ children?: ReactNode; } & DispatchProp<any>>''typeof test' 类型的参数不可分配给'Component<{ children?: ReactNode; 类型的参数} & DispatchProp<任何>>'
【发布时间】:2018-01-01 12:37:24
【问题描述】:
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'。

【问题讨论】:

标签: reactjs typescript redux react-redux


【解决方案1】:

看起来你过度设计了你的组件;它根本不需要connect 来redux,因为它不使用状态或调度。此外,错误本身是指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>
        );
    }
}

【讨论】:

  • 非常感谢您的回答
猜你喜欢
  • 2020-01-06
  • 2020-08-25
  • 2022-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-15
  • 2021-10-29
相关资源
最近更新 更多