5

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?

2

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.