简体   繁体   English

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

[英]Binding element 'input' implicitly has an 'any' type in redux form

I am new to React with Typescript i am trying to create a redux form component.But when it is compiled i am getting the error as below 我是使用Typescript刚接触React的人,我试图创建一个Redux表单组件。但是当它被编译时,我得到了如下错误

在此处输入图片说明

I have tried to add props as below but i don't know whether the approach is correct or not. 我试图添加道具如下,但我不知道该方法是否正确。

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>
);
import {InjectedFormProps} from 'redux-form';
interface FormInputProps {/*other local thing*/} extends InjectedFormProps;

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

Found the answer: Tried like below and it works fine 找到了答案:尝试如下,效果很好

  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;

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM