formik
formik copied to clipboard
Add generic type to FieldArray types.
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.
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.
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. :(
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
can you please rebase with the latest master and also resolve the conflict
https://github.com/formium/formik/pull/3401
What's the status?
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