Joaquim d'Souza
Joaquim d'Souza

Reputation: 1516

react-i18next and typescript 4.1

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

Answers (1)

V&#237;t Zadina
V&#237;t Zadina

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

Related Questions