绑定元素“输入”隐式地具有redux形式的“任意”类型

时间:2019-05-02 10:10:35

标签: reactjs typescript redux-form

我是使用Typescript刚接触React的人,我试图创建一个Redux表单组件。但是当它被编译时,出现如下错误

enter image description here

我尝试如下添加道具,但我不知道这种方法是否正确。

interface FormInputProps {
  input: any,
  iconName: string,
  placeHolder: string,
  inputType: string,
  meta: object,
}
const FormInput = ({
  input,
  iconName,
  placeHolder,
  inputType,
  meta: { error, touched }
}) => (
  <FormGroup>
    <InputGroup className="mb-3">
      <InputGroupAddon addonType="prepend">
        <InputGroupText>
          <i className={iconName}/>
        </InputGroupText>
      </InputGroupAddon>
      <Input
        {...input}
        type={inputType}
        placeholder={placeHolder} />
    </InputGroup>
    {touched && <FormText className="help-block error-color">{error}</FormText>}
  </FormGroup>
);

2 个答案:

答案 0 :(得分:1)

import {InjectedFormProps} from 'redux-form';
interface FormInputProps {/*other local thing*/} extends InjectedFormProps;

const FormInput:React.FC<FormInputProps> = ()=>{...}

答案 1 :(得分:0)

找到答案: 尝试如下所示,效果很好

  const FormInput = (field: any) => (
  <FormGroup>
    <InputGroup className="mb-3">
      <InputGroupAddon addonType="prepend">
        <InputGroupText>
          <i className={field.iconName}/>
        </InputGroupText>
      </InputGroupAddon>
      <Input
        {...field.input}
        type={field.inputType}
        placeholder={field.placeHolder} />
    </InputGroup>
    {field.touched && <FormText className="help-block error-color">{field.error}</FormText>}
  </FormGroup>
);

export default FormInput;