简体   繁体   English

类型React:类型&#39;profile&#39;的参数不能分配给&#39;ComponentType类型的参数 <never> &#39;

[英]Type React: Argument of type 'profile' is not assignable to parameter of type 'ComponentType<never>'

I'm new to typescript and this issues has me stumped. 我是打字稿新手,这个问题让我感到难过。 Here's my code. 这是我的代码。

import { IProps, IState }   from './types';

class Profile extends Component<RouteComponentProps & IProps, IState>{
    state: IState = {
        form: {
            first_name: this.props.user.first_name,
            last_name : this.props.user.last_name,
            email     : this.props.user.email,
            phone     : this.props.user.phone || ''
        },

        isLoading: false
    };

    validator = new SimpleReactValidator({autoForceUpdate: true});


    render () {
        const { user } = this.props;
        const { form, isLoading } = this.state;

        return (<div></div>)
    }
}

export default Profile;

These are my types: 这些是我的类型:


export interface IState {
    form: {
        [key: string]: any;
    };

    isLoading: boolean;
}

export interface IProps {
    children?: Element;
    user    : any;
}

And this is my index.ts: 这是我的index.ts:

import Profile       from './pages/profile/Profile';

const mapStateToProps = (state: IAppState) => {
    return {
        user: state.Auth.user
    };
};

export default connect(mapStateToProps)(Profile);

My code editor highlights that (Profile) as an error. 我的代码编辑器突出显示该(配置文件)为错误。

My terminal throws out the following error: 我的终端抛出以下错误:

Argument of type 'typeof Profile' is not assignable to parameter of type >'ComponentType'. 类型'typeof Profile'的参数不能分配给类型>'ComponentType'的参数。 Type 'typeof Profile' is not assignable to type 'ComponentClassany>'. 类型'typeof Profile'不能分配给类型'ComponentClassany>'。

I'd like to know if there is a code change I can make here to fix this Typescript "error". 我想知道是否可以在这里进行代码更改以解决此Typescript“错误”。

import { IProps, IState }   from './types';
import {connect} from "react-redux"

class Profile extends Component<RouteComponentProps & IProps, IState>{
    state: IState = {
        form: {
            first_name: this.props.user.first_name,
            last_name : this.props.user.last_name,
            email     : this.props.user.email,
            phone     : this.props.user.phone || ''
        },

        isLoading: false
    };

    validator = new SimpleReactValidator({autoForceUpdate: true});


    render () {
        const { user } = this.props;
        const { form, isLoading } = this.state;

        return (<div></div>)
    }
}


const mapStateToProps = (state: IAppState) => {
    return {
        user: state.Auth.user
    };
};

export default connect(mapStateToProps)(Profile);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “Function”类型的参数不能分配给“ComponentType”类型的参数<never> &#39; - Argument of type 'Function' is not assignable to parameter of type 'ComponentType<never>' 'FC 类型的参数<componenttype> ' 不能分配给 'ForwardRefRenderFunction 类型的参数<unknown, componenttype> '</unknown,></componenttype> - Argument of type 'FC<ComponentType>' is not assignable to parameter of type 'ForwardRefRenderFunction<unknown, ComponentType>' React TypeScript:参数不可分配给“从不”类型的参数 - React TypeScript: Argument is not assignable to parameter of type 'never' React Typescript 错误“元素”类型的参数不可分配给“组件类型”类型的参数<unknown> '</unknown> - React Typescript Error Argument of type 'Element' is not assignable to parameter of type 'ComponentType<unknown>' Typescript React / Redux:类型&#39;typeof MyClass&#39;的参数不能赋值给&#39;ComponentType &lt;...&#39;类型的参数 - Typescript React/Redux : Argument of type 'typeof MyClass' is not assignable to parameter of type 'ComponentType<…' 类型参数不可分配给“SetStateAction”类型的参数<never[]> &#39;。 在反应中 - Argument of type is not assignable to parameter of type 'SetStateAction<never[]>'. in React 与 Typescript 反应:“never[]”类型的参数不可分配给“StateProperties |”类型的参数 (() =&gt; 状态属性)' - React with Typescript: Argument of type 'never[]' is not assignable to parameter of type 'StateProperties | (() => StateProperties)' “文件”类型的参数不能分配给“从不”类型的参数。 与 TypeScript 反应 - Argument of type 'File' is not assignable to parameter of type 'never'. React with TypeScript “状态”类型的参数不能分配给“从不”类型的参数 - Argument of type 'State' is not assignable to parameter of type 'never' “ typeof LogoAvatar”类型的参数不能分配给“ ComponentType”类型的参数<LogoProps & Partial<WithTheme> - Argument of type 'typeof LogoAvatar' is not assignable to parameter of type 'ComponentType<LogoProps & Partial<WithTheme>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM