verbal-limeV
Refine14mo ago
15 replies
verbal-lime

i18n provider doesn't match the types from i18next

The type that refine expects in the I18nProvider, the translate key doesn't match the type of the 18next t function.

Getting the following error:
Type '(key: string, options?: any, defaultMessage?: string) => string | $SpecialObject | TFunctionDetailedResult<string | $SpecialObject, any>' is not assignable to type 'TranslateFunction'.
  Type 'string | $SpecialObject | TFunctionDetailedResult<string | $SpecialObject, any>' is not assignable to type 'string'.
    Type 'object' is not assignable to type 'string'.ts(2322)
types.d.ts(5, 5): The expected type comes from property 'translate' which is declared here on type 'I18nProvider'
    Type 'object' is not assignable to type 'string'.ts(2322)

In this code taken directly from the documentation page:
  const i18nProvider: I18nProvider = {
    translate: (key: string, options?: any, defaultMessage?: string) =>
      t(key, defaultMessage, options),
    changeLocale: (lang: string) => i18n.changeLanguage(lang),
    getLocale: () => i18n.language,
  }
Was this page helpful?