reactjs - 类型 'typeof test' 的参数不可分配给类型 'Component<{ children?: ReactNode; } & DispatchProp<any>>' 的参数

标签 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); 

错误

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/

相关文章:

angular - ngFor 和 *ngFor 有什么区别

javascript - 如何知道用户是否使用 reactjs 连接到蜂窝网络或 wifi

javascript - @reach/router 嵌套 protected 路由

typescript - Typescript 中的链接 Promise

javascript - React/Redux - 无限滚动/从 API 加载更多

javascript - 带yield的条件赋值

javascript - 与 react/redux 共享 actions 和 reducers

javascript - 如何为 React 组件设置默认样式

reactjs - usePagination 自定义 Hook 与 material-ui 使用分页组件中的 next 和 prev 函数作为 Prop

angular - 在 Angular 2 中使用 @HostBinding 动态更改正文类