setLocale({
// use constant translation keys for messages without values
mixed: {
default: 'field_invalid',
},
// use functions to generate an error object that includes the value from the schema
number: {
min: ({ min }): YupValue => ({ key: 'field_too_short', values: { min } }),
max: ({ max }): YupValue => ({ key: 'field_too_big', values: { max } }),
},
});
Expected Type:
// my-port-yop, this can be typed much better
type YupValue = { key: TValues[keyof TValues], values: any };
// vee-validate
declare type FormErrors<TValues extends Record<string, unknown>> = Partial<Record<
keyof TValues,
YupValue
>>;
useForm({
validationSchema: markRaw(
io.object({
password: io.string().required().min(2),
})
),
}).errors.password // string | undefined, but real type is { key: 'field_too_short', values: { min } }
Why i use object as result?
For custom t(password.key, password.values) in view.
For t(password.key, { ...password.values, path: t(password.values.path) }) when path translation defined in component.
Yup exemple from docs using-a-custom-locale-dictionary:
Expected Type:
Current Type:
Exemple:
Why i use object as result?
t(password.key, password.values)
in view.t(password.key, { ...password.values, path: t(password.values.path) })
when path translation defined in component.