4

I'm having trouble figuring out how to use react-i18next with typescript 4.1.

According to the docs, I should be able to do:

const { t } = useTranslation();
return <h1>{t('title')}</h1>

However, that call to t errors:

No overload matches this call: Argument of type 'string' is not assignable to parameter of type 'never'.

What does work is using either:

useTranslation<string>()

or

useTranslation('translation')

Both of these seem unnecessary qualifications.

This seems to only be the case with typescript 4, as if I downgrade to typescript 3 the error goes away.

Is there a way to use the shorter useTranslation() in typescript 4?

Joaquim d'Souza
  • 1,416
  • 2
  • 14
  • 25
  • did you see this ?? : https://stackoverflow.com/questions/58277973/how-to-type-check-i18n-dictionaries-with-typescript – Robert Dec 07 '20 at 17:11
  • This appears to be a bug in the latest release of react-i18next. See [#1213 (typescript) Template literals no longer work post 11.8.0](https://github.com/i18next/react-i18next/issues/1213) – olav Dec 08 '20 at 12:58

1 Answers1

2

I know this is probably late, but there is very good boilerPlate for starting react typescript i18next app. Check this github - https://github.com/Lemoncode/i18next-example-typescript

Vít Zadina
  • 168
  • 8