Open olliechick opened 1 year ago
Currently, MessageParams is defined as:
export interface MessageParams { path: string; value: any; originalValue: any; label: string; type: string; spec: SchemaSpec<any> & Record<string, unknown>; }
This means that when using setLocale to set translatable strings to validation messages, we can't guarantee type safety. For example, I use i18next to translate strings. If I try to pass in the type like this:
setLocale
setLocale({ mixed: { notType: params => t('enterType', { type: t(params.type) }) } });
with a translation file containing:
export default { common: { enterType: 'Please enter a {{type}}', number: 'number', string: 'string', // more to account for all types } }
it results in a type error, because it cannot guarantee that when I pass in params.type to the t function that it will result in a valid translation.
params.type
t
Change the type of type to something like this:
type
type: 'string' | 'number' | //todo the rest of the possible values
Currently, MessageParams is defined as:
This means that when using
setLocale
to set translatable strings to validation messages, we can't guarantee type safety. For example, I use i18next to translate strings. If I try to pass in the type like this:with a translation file containing:
it results in a type error, because it cannot guarantee that when I pass in
params.type
to thet
function that it will result in a valid translation.Suggested change
Change the type of
type
to something like this: