Form errors are currently of type string. In most other form validation libraries I've used this is an any type so a user could do things like the following:
setErrors({
password: ['Must be more than 8 characters', 'Must contain a special character']
})
or for localization:
setErrors({
password: [{type: 'min', min: 3, value: 1}]
})
setErrors({
password: [{localizationKey: 'blah', value: 1}]
})
Is there any reason why it needs to strictly be of type string? It actually works setting it to whatever I want so long as I cast it but makes working with TypeScript funky and limits the flexibility of users.
Similar to #1244, #1293
Errors are not limited to strings. You can use whatever data structure you wish. As you mentioned, we should fix TS typings to not complain about this.
Yes, understood (as I mentioned in the original post It actually works setting it to whatever I want so long as I cast).
It's just the types are wrong ATM:
export type FormikErrors<Values> = {
[K in keyof Values]?: Values[K] extends object
? FormikErrors<Values[K]>
: string
};
setErrors(errors: FormikErrors<Values>): void;
setFieldError(field: keyof Values & string, message: string): void;
setFieldError(field: string, message: string): void;
Closing due to long inactivity
Most helpful comment
Yes, understood (as I mentioned in the original post
It actually works setting it to whatever I want so long as I cast).It's just the types are wrong ATM: