-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
TS2589: Type instantiation is excessively deep and possibly infinite.
with Typescript 4.5.2 and react-i18next 11.14.3
#1417
Comments
I did, that's why I'm opening yet another issue on that subject. |
The typescript team improved the way recursive types work, but it seems there are still some limitations. I'll try to find a workaround to suppress the error. |
Hey guys, I didn't manage to find a way to suppress the error, typescript team increased the number of recursive type instantiations from 1 - Call const { t } = useTranslation(["ns1"]);
return (
<div className="App">
{Trans({ t, i18nKey: "ns1:name", children: <h1>Weird</h1> })}
</div>
); 2 - Add a ts-ignore (don't recommend) <div className="App">
{/* @ts-ignore */}
<Trans i18nKey="ns10:name" t={t}>
<h1>Weird</h1>
</Trans>
</div> 3 - Use patch-package, to increase the number of instances here to something like: if (instantiationDepth === 200 || instantiationCount >= 5000000) { You can find more info about the discussion here: microsoft/TypeScript#34933 |
I don't have too many namespaces, I just have two, so where does my problem lives then? Something to note is that my keys are deeply nested, can that be the root of the problem? They can look something like this: t('OneOffPayItemForm.details.title.label') |
Hey @danielo515, that can also happen if there is something wrong with your configuration ( |
Hello @pedrodurek , thanks for your answer. This is my import 'react-i18next';
import translation from './locales/en/translation.json';
import toast from './locales/en/toasts.json';
declare module 'react-i18next' {
interface CustomTypeOptions {
defaultNS: 'translation';
resources: {
translation: typeof translation;
toast: typeof toast;
};
}
} If you have a condesandbox template I will happily try to reproduce my problem there. |
I just reproduced the issue on a codesandbox and, while trying to slim down my translation file to not expose too much information a bit I accidentally fixed it. I'll do a diff of the files to see if I can determine where the problem is |
Ok, now I think I fixed it on my own repository too. Seems that my import path on the |
Hi And got rid on of the annoying |
Hello. I think I am facing again an issue related to this problem (this time for real). |
Hey @danielo515, can you create a similar (as nested as yours is) example on codesanbox, so I can investigate it? |
Sure @pedrodurek , do you have any template? |
You can use this one https://codesandbox.io/s/react-i18next-typed-keys-bug-forked-x77zq |
I already started one, but thank you very much |
Here you have a sandbox. It is only complaining about the excessively deep problem, but if you try to run type-check locally it will blow up node: |
@danielo515 same issue here, subscribing |
Hello.
|
Experienced the same issue, the reason was similar to the one @danielo515 had. In my case, it happened due to unexported resources: |
Ah thanks @the-night-wing and @tiavina-mika I didn't set this stuff up and noticed it was |
Edit: Best solution is to update to version 12. It finally fixes this problem. I found two workarounds to get rid of the error when using the // before
const {t} = useTranslation(['foo', 'bar'])
// workaround 1 - explicit typing
const {t} = useTranslation<['foo', 'bar']>(['foo', 'bar'])
// or
const {t} = useTranslation<('foo' | 'bar')[]>(['foo', 'bar'])
// workaround 2 - use any
const {t} = useTranslation<any>(['foo', 'bar']) |
@mstuercke sounds like you are avoiding the types completely with your workaround. You could've just deleted the react-i18next.d.ts file entirely and have the same effect. |
@kai-dorschner-twinsity You're right. I see it as a temporary fix until there is a better solution. I'm not a fan of that workaround either. |
fyi: #1501 |
That fixed the issue for me on v15.4 |
🐛 Bug Report
Using a
<Trans>
component with a lot of namespaces trigger the following typescript error:The error starts to happen as soon as there's more than 45 namespaces.
You can check this behavior by modifiying the following file: https://github.com/xseignard/react-i18n-ts-bug-repro/blob/main/src/i18n/locales/en/index.ts
ns0
tons44
and there's no errorsns0
tons45
(or more) and the error popsRelated issue comment: #1394 (comment)
To Reproduce
Here is a repo to repro: https://github.com/xseignard/react-i18n-ts-bug-repro
Expected behavior
No typescript error
Your Environment
The text was updated successfully, but these errors were encountered: