gpt4 book ai didi

reactjs - Redux-Form v7 Field 组件 typescript 错误

转载 作者:搜寻专家 更新时间:2023-10-30 20:53:09 25 4
gpt4 key购买 nike

这是我使用 Field 组件的代码:

    interface EditProfileFormProps extends FormProps {
defaults: object;
submit: () => {};
initialValues: object;
roles: object[];
specialties: object[];
}

const EditProfileForm: React.StatelessComponent<EditProfileFormProps> = (props: EditProfileFormProps) => {
return (
<Form onSubmit={props.submit}>
<div>
<Field name="firstName" component={FirstName} type="text" />
</div>
<div>
<Field name="lastName" component={LastName} type="text" />
</div>
<div>
<Field name="role" props={{ roles: props.roles }} component={Role} type="select" />
</div>
</Form>
);
};

//FirstName.tsx
export const FirstName: React.StatelessComponent<React.InputHTMLAttributes<HTMLInputElement>> = ({
input,
}: React.InputHTMLAttributes<HTMLInputElement> & WrappedFieldProps) => (
<FormGroup>
<Label for="firstName">First Name</Label>
<Input {...input} type="text" name="firstName" id="firstName" />
</FormGroup>
);

这是我看到的 TS 错误:

[ts]
Type '{ name: "firstName"; component: StatelessComponent<InputHTMLAttributes<HTMLInputElement>>; type: ...' is not assignable to type '(IntrinsicAttributes & IntrinsicClassAttributes<Field<GenericFieldHTMLAttributes>> & Readonly<{ c...'.
Type '{ name: "firstName"; component: StatelessComponent<InputHTMLAttributes<HTMLInputElement>>; type: ...' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Field<GenericFieldHTMLAttributes>> & Readonly<{ ch...'.
Type '{ name: "firstName"; component: StatelessComponent<InputHTMLAttributes<HTMLInputElement>>; type: ...' is not assignable to type 'Readonly<BaseFieldProps<GenericFieldHTMLAttributes> & TextareaHTMLAttributes<HTMLTextAreaElement>>'.
Types of property 'component' are incompatible.
Type 'StatelessComponent<InputHTMLAttributes<HTMLInputElement>>' is not assignable to type '"input" | "select" | "textarea" | ComponentClass<GenericFieldHTMLAttributes> | StatelessComponent...'.
Type 'StatelessComponent<InputHTMLAttributes<HTMLInputElement>>' is not assignable to type 'StatelessComponent<GenericFieldHTMLAttributes>'.
Type 'React.ReactElement<any> | null' is not assignable to type 'React.ReactElement<any> | null'. Two different types with this name exist, but they are unrelated.
Type 'ReactElement<any>' is not assignable to type 'ReactElement<any> | null'.
Type 'React.ReactElement<any>' is not assignable to type 'React.ReactElement<any>'. Two different types with this name exist, but they are unrelated.
Types of property 'type' are incompatible.
Type 'string | React.ComponentClass<any> | React.StatelessComponent<any>' is not assignable to type 'string | React.ComponentClass<any> | React.StatelessComponent<any>'. Two different types with this name exist, but they are unrelated.
Type 'ComponentClass<any>' is not assignable to type 'string | ComponentClass<any> | StatelessComponent<any>'.
Type 'ComponentClass<any>' is not assignable to type 'StatelessComponent<any>'.
Type 'ComponentClass<any>' provides no match for the signature '(props: any, context?: any): ReactElement<any> | null'.

有人看到我做错了什么吗?

最佳答案

不确定这是否是您的问题,但是当我们制作无状态组件时,我们的签名看起来像这样 React.SFC 而不是 React.StatelessComponent

关于reactjs - Redux-Form v7 Field 组件 typescript 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47719472/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com