react-final-form icon indicating copy to clipboard operation
react-final-form copied to clipboard

validateFields is missing in the type definition of FieldProps

Open micurs opened this issue 8 years ago • 3 comments

bug report

Missing validateFields in type definition for FieldProps

When I try to compile a Field using validateFields={[]} the TypeScript compiler gives me an error:

error TS2339: Property 'validateFields' does not exist on type 'IntrinsicAttributes & { allowNull?: boolean | undefined; format?: ((value: any, name: string) => ...'.

My sample code is:

  <Field name="last_name" validate={this.validateRequired} validateFields={[]}>
    {( { meta, input } ) => (
      <input
         type="text"
         className={(!meta.pristine || meta.touched ? meta.error || 'Valid' : '' ) as string}
         {...input}
      />)}
  </Field>

I changed the FieldProps definition in index.d.ts and the error went away:

export type FieldProps = {
  allowNull?: boolean
  format?: ((value: any, name: string) => any) | null
  parse?: ((value: any, name: string) => any) | null
  name: string
  subscription?: FieldSubscription
  validate?: (value: any, allValues: object) => any
  value?: any
  validateFields?: string[]
} & RenderableProps<FieldRenderProps>

Can you confirm? I can submit a PR with the change if ok with you.

Thank you Michele

micurs avatar Dec 28 '17 22:12 micurs

Confirm this. Just was about to report the same...

Types definition

yurist38 avatar Dec 05 '18 10:12 yurist38

I just had a look at it and it's actually kinda weird.

https://github.com/final-form/react-final-form/blob/master/src/types.js.flow#L89

It takes a definition of validate method from final-form package. The strange thing here is that final-form has meta inside:

https://github.com/final-form/final-form/blob/master/src/types.js.flow#L111

Any idea why it can happen?

yurist38 avatar Dec 05 '18 10:12 yurist38

Solved in recent versions

gertdreyer avatar Mar 02 '23 18:03 gertdreyer