Reputation: 1516
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?
Upvotes: 5
Views: 4098
Reputation: 562
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
Upvotes: 1