Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type errors when doing interpolation in react-typescript/simple #1598

Closed
adr29truck opened this issue Dec 22, 2022 · 24 comments · Fixed by i18next/i18next#1911
Closed

Type errors when doing interpolation in react-typescript/simple #1598

adr29truck opened this issue Dec 22, 2022 · 24 comments · Fixed by i18next/i18next#1911

Comments

@adr29truck
Copy link

adr29truck commented Dec 22, 2022

🐛 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 adr29truck@24a615a 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
@adrai
Copy link
Member

adrai commented Dec 22, 2022

Sorry, but I'm not able to reproduce it...
98b118b#diff-ac4dc9bfd1bf289f94946a467ac5c76f365692d68cc9ca9258f7c6396a598f9e

@adr29truck
Copy link
Author

adr29truck commented Dec 22, 2022

@adrai Thanks for taking a look.

So when checking out the new commit, It raises an error in VSCode only. Typescript does not fail to compile.
If I however try using translation:title instead of title as the key then typescript fails to compile all together with the second error. (see screenshot)
Screenshot 2022-12-22 at 16 12 04

If I then provide it a deaultValue (so we get {name: 'John', defaultValue: 'Adam'}) the second error goes away and it now only raises Type instantiation is excessively deep and possibly infinite. but does not fail to compile.

@adrai
Copy link
Member

adrai commented Dec 22, 2022

fyi: this works:
image

@adr29truck
Copy link
Author

fyi: this works: image

Yeah, that compiles, but it still raises the possibly infinite error
Screenshot 2022-12-22 at 16 51 00

@marakim
Copy link

marakim commented Dec 27, 2022

I am also seeing this problem on "i18next": "^22.4.6"

@marakim
Copy link

marakim commented Dec 27, 2022

Any form of interpolation gives the "excessively deep" type error.

@marakim
Copy link

marakim commented Dec 27, 2022

This is with "react-i18next": "^12.1.1"

@pedrodurek
Copy link
Member

Hey @adr29truck, I also didn't manage to reproduce it, and I'm using the latest vscode version. My assumption is that there is a conflict with one of your vscode extensions. Could you share your extension list, please?

@farmerpaul
Copy link

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.

@DumasOlivier
Copy link

Exactly the same error here ...
"i18next": "^22.4.9" "react-i18next": "^12.1.4"

@DumasOlivier
Copy link

DumasOlivier commented Jan 17, 2023

Update, I managed to make it work using this code:

// Type instantiation is excessively deep and possibly infinite.ts(2589)
<div>
  {t('key2', {count: myCounter})}
</div>

// No error
import {Trans, useTranslation} from 'react-i18next';

...
  const {t} = useTranslation('key1');
...

<div>
  {Trans({t, i18nKey: 'key2', count: myCounter})}
</div>

@cainlevy
Copy link

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

@bencerf
Copy link

bencerf commented Feb 1, 2023

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.

@stale
Copy link

stale bot commented Feb 18, 2023

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.

@stale stale bot added the stale label Feb 18, 2023
@stale stale bot closed this as completed Mar 18, 2023
@adrai adrai removed the stale label Mar 18, 2023
@adrai adrai reopened this Mar 18, 2023
@stale
Copy link

stale bot commented Apr 3, 2023

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.

@adrai adrai added stale and removed stale labels Apr 3, 2023
@bencerf
Copy link

bencerf commented Apr 10, 2023

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.

Well.. we still have problem ! We temporally fix the problem with the workaround 1 & 2 listed here : #1417 (comment).
Like @adr29truck said, it compiles but it still raises the possibly infinite error warning...

@stale
Copy link

stale bot commented Apr 26, 2023

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.

@stale stale bot added the stale label Apr 26, 2023
@adrai adrai removed the stale label Apr 26, 2023
@stale
Copy link

stale bot commented May 8, 2023

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.

@stale stale bot added the stale label May 8, 2023
@adrai adrai removed the stale label May 9, 2023
@stale
Copy link

stale bot commented May 20, 2023

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.

@stale stale bot added the stale label May 20, 2023
@adrai adrai removed the stale label May 20, 2023
@bencerf
Copy link

bencerf commented Jun 2, 2023

@adrai do we have any news about this issue ? It still compiles but still raises the possibly infinite error warning...

@adrai
Copy link
Member

adrai commented Jun 2, 2023

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

@bencerf
Copy link

bencerf commented Jun 2, 2023

Amazing, thanks a lot for the follow-up !

@bencerf
Copy link

bencerf commented Jun 14, 2023

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

@adrai I see that this PR is still in Draft but you close this issue. I means Type instantiation is excessively deep and possibly infinite. is now fixed or still raises the possibly infinite error warning ?

Thanks in advance for your answer 🙂

@adrai
Copy link
Member

adrai commented Jun 14, 2023

@MiryksV with the next major release this is fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants