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);
错误
Argument of type 'typeof test' is not assignable to parameter of type 'Component<{ children?: ReactNode; } & DispatchProp>'.
最佳答案
看起来您对组件进行了过度设计;它根本不需要 connect
到 redux,因为它既不使用 state 也不使用 dispatch。此外,错误本身是指 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>
);
}
}
关于reactjs - 类型 'typeof test' 的参数不可分配给类型 'Component<{ children?: ReactNode; } & DispatchProp<any>>' 的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45322713/