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;”。
答案 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>
);
}
}