类型'FunctionComponent <wrappedfieldprops&=“” iprops =“”>'不可分配给类型'(“ input”&FunctionComponent

时间:2019-01-15 11:02:02

标签: typescript redux redux-form

能帮我请您理解并修复错误

我使用打字稿,webpack,redux形式。 运行webpack-dev-server --mode development时出现编译错误。

它已编译,但是我删除了node_modules文件夹并yarn installyarn.lock未被删除。

InputField.ts

import React from 'react';
import {WrappedFieldProps} from 'redux-form';

interface IProps {
    label: string,
}

const InputField: React.FC<WrappedFieldProps & IProps> = ({
    label,
}) => {

    return (
        <div className="form-control">
            <label>
                {label}:
            </label>
        </div>
    );
};

export default InputField;

表单组件

import InputField from 'Field/InputField';

render() {
        return (
                <form onSubmit={handleSubmit}>
                    <Field
                        component={InputField}
                        name="email"
                        label="E-mail"
                    />

错误

 TS2322: Type 'FunctionComponent<WrappedFieldProps & IProps>' is not assignable to type '("input" & FunctionComponent<WrappedFiel

dProps & IProps>) | ("select" & FunctionComponent<WrappedFieldProps & IProps>) | ("textarea" & FunctionComponent<WrappedFieldProps & I

Props>) | (ComponentClass<...> & FunctionComponent<...>) | (FunctionComponent<...> & FunctionComponent<...>)'.
  Type 'FunctionComponent<WrappedFieldProps & IProps>' is not assignable to type '"input" & FunctionComponent<WrappedFieldProps & IPro

ps>'.
    Type 'FunctionComponent<WrappedFieldProps & IProps>' is not assignable to type '"input"'.

2 个答案:

答案 0 :(得分:0)

定义类似组件

const InputField = (props: WrappedFieldProps & IProps) => {

恕我直言,@ typings / redux-form似乎有问题

答案 1 :(得分:0)

尝试一下 npm卸载redux-form npm安装redux-form