react-i18next: Type errors when doing interpolation in react-typescript/simple

πŸ› Bug Report

Using the simple react-typescript example and introducing a variable to interpolate in the translation file causes Type instantiation is excessively deep and possibly infinite. or 'TFunctionDetailedResult<never>' is not assignable to type 'ReactI18NextChild | Iterable<ReactI18NextChild>'. Property '[Symbol.iterator]' is missing in type 'TFunctionDetailedResult<never>' but required in type 'Iterable<ReactI18NextChild>' to be raised

To Reproduce

Using the simple react-typescript example in this repo, introduce a variable in the translation file

{
  "title": "Welcome to react using react-i18next fully type-safe",
  "description": {
    "part1": "This is a simple example. {{hello}}",
    "part2": "πŸ˜‰"
  }
}

then in app.tsx try accessing description.part1 using the t function derived from useTranslation.

<p>{t('description.part1', {hello: 'string'})}</p>

or

<p>{t('translation:description.part1', {hello: 'string'})}</p>

respectively.

See this commit https://github.com/adr29truck/react-i18next/commit/24a615a6bc1b56b133e06cefdf21662efc7e4d82 on fork

Expected behavior

It should not raise type errors.

Your Environment

  • runtime version: node v16.13.0, chrome
  • i18next version: ^22.4.3
  • react-i18next version: ^12.1.1
  • os: Mac

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 8
  • Comments: 24 (5 by maintainers)

Most upvoted comments

As soon as this PR (and this) lands, we can get to this.

I solved this by updating to at least typescript@4.7.2.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@MiryksV with the next major release this is fixed

I solved this by updating to at least typescript@4.7.2.

Confirmed ! We could not use more than 45 namespace/.json files… We had this problem in our project using typescript@4.6.3 by, after bumping, no more problem.

In my experience, this issue occurs both in VS Code, and when running tsc – @adrai’s suggested workaround doesn’t work to solve the issue in either case.

However, the moment I downgraded react-18n from v12 to v11.18.6, it was solved, and that suits me fine for now.