formik icon indicating copy to clipboard operation
formik copied to clipboard

Add generic type to FieldArray types.

Open IronSean opened this issue 4 years ago • 5 comments

I added a generic type to the FieldArrayRenderProps type and the ArrayHelpers type.

This will allow usage of FieldArray like this:

<FieldArray name={"myArrayFieldName"}>
  {(fieldArrayProps: FieldArrayRenderProps<MyFormType, MyFieldArrayType>)  => {
    fieldArrayProps.form; //typed as FormikProps<MyFormType> instead of FormikProps<any>
    fieldArrayProps.push; //takes a typed input object of MyFieldArrayType
    fieldArrayProps.pop; //returns an object of type MyFieldArrayType
    return (
      //My componenets    
  )}}
</FieldArray>

However, because of the existing generic property on pop and remove, to allow adding types just on the pop/remove calls, this may be a breaking change. as I had to change it from pop<T>(): T | undefined; to pop: () => T | undefined

Fixes #911, as well as making the FieldArray component able to be type checked in TypeScript.

IronSean avatar Nov 01 '19 16:11 IronSean

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

codesandbox-ci[bot] avatar Nov 01 '19 16:11 codesandbox-ci[bot]

Hi, thanks for working on this. We recently found out by surprise that ArrayHelpers is not type-safe in TypeScript.

Really looking forward to when this is merged. But it's almost a year later and nobody has shown interest. :(

intgr avatar Oct 22 '20 11:10 intgr

Hey @IronSean sorry for the late response, can you please rebase with the latest master and also resolve the conflict

would be pleasured to review

maddhruv avatar Oct 22 '20 11:10 maddhruv

can you please rebase with the latest master and also resolve the conflict

https://github.com/formium/formik/pull/3401

Philipp91 avatar Nov 07 '21 10:11 Philipp91

What's the status?

mateuszpigula avatar Apr 15 '22 12:04 mateuszpigula

I am closing this because we stopped using Formik a couple years ago and I have no idea how relevant it is or isn't anymore

IronSean avatar Dec 20 '22 20:12 IronSean