Description
🐛 Bug report
The FieldProps
types has undocumented breaking changes. Previously it accepted a single generic for the FormValues
, but now it accepts two generics with defaults. This leads to breakage since the default any
will be used for the second generic and FormValues
is used for the field type. This is not mentioned in the migration guide or breaking changes for v2.
Current Behavior
FieldProps<FormValues>
gives field.value
typed as FormValues
. Since FieldProps
has default generics, the required change is not obvious.
Expected behavior
form.values
and not field.value
is types with FormValues
. Alternatively, it should be mentioned as a breaking change in the migration giude / changelog.
Reproducible example
Pass a single generic to FieldProps
as done in < v2.
Suggested solution(s)
Document this breaking change.
Additional context
The current type for FieldProps
export interface FieldProps<V = any, FormValues = any> {
field: FieldInputProps<V>;
form: FormikProps<FormValues>; // if ppl want to restrict this for a given form, let them.
meta: FieldMetaProps<V>;
}
The previous type:
export interface FieldProps<V = any> {
field: {
/** Classic React change handler, keyed by input name */
onChange: FormikHandlers['handleChange'];
/** Mark input as touched */
onBlur: FormikHandlers['handleBlur'];
/** Value of the input */
value: any;
/* name of the input */
name: string;
};
form: FormikProps<V>; // if ppl want to restrict this for a given form, let them.
}
Your environment
Software | Version(s) |
---|---|
Formik | 2.1.2 |
React | not relevant |
TypeScript | 3.8.2 |
Browser | not executed in browser |
npm/Yarn | yarn 1.21.1 |
Operating System | Ubuntu 19.10 |