Open Gnomeek opened 2 months ago
Another idea comes to my mind. We can implement a ExtractArrayTypes<T>
which extracts all types(include nested) in T that extends Array
, thus:
export type FieldArrayRenderProps<
Values extends FormikValues,
T extends ExtractArrayTypes<Values>
> = ArrayHelpers<T> & {
form: FormikProps<Values>;
name: string;
};
Feature request
Hi team, I'd like to propose an improvement on
<FieldArray />
orFieldArrayRenderProps
to make it type-safer.Current Behavior
Currently, we only have generic type on
ArrayHelpers
https://github.com/jaredpalmer/formik/blob/2618cc4e6af0b2b1fcbff93936b5d3c68809b791/packages/formik/src/FieldArray.tsx#L20-L31Desired Behavior
T
ofArrayHelpers<T>
should be inferred fromFieldArrayRenderProps
.Suggested Solution
Maybe we can leverage knowledge from
Get
from type-fest to achieve something like:Who does this impact? Who is this for?
A type-safer
<FieldArray />
orFieldArrayRenderProps
can improve the type coverage of the package and avoid lots of unsafe cases.Corner cases
For nested object