-
-
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
TS throw Type instantiation is excessively deep and possibly infinite
when there are loads of keys
#1222
Comments
Type instantiation is excessively deep and possibly infinite
when the keys are to muchType instantiation is excessively deep and possibly infinite
when the keys are to much
@pedrodurek you got an idea? |
Isn't this caused by a namespace? I believe namespaces are not supported by type checking currently — I may be wrong though 🙂 |
Hey @DCzajkowski, actually it does. It supports all cases, single, multiple and no namespace passed. And without augmentation the Resources type, it should work as before in the v11.7.4. So this feature which types all |
Good to know namespaces are supported, thanks!
Hm, it didn't work for me. Without type augmentation I was getting type errors for keys :/ I can give you more information, but I don't have time at this moment. Let me know 😉 |
Hey @jigsawye, we've performed tests with more them 5k keys and it worked perfectly, so 2.5k keys shouldn't be a problem. Could you provide some extra info so we can test the closest scenario that you have there? 1 - Do you know approximately how deep the keys are?
3 - How many namespaces do you have? We're working on the documentation for these new types. So it'd be great to know whether there is a limitation or not. If there is, our idea is to report those limitations to the Typescript team and add that to the documentation. |
Hey @DCzajkowski, even using the last version v11.8.3? If so, could you post the error here? |
@pedrodurek Thanks for letting me know. I have just upgraded to v11.8.3 and there are no breaking changes anymore, yay! Just FYI: the initial error I was getting was not caused by type checking on keys, but on our usage of the |
Hi @pedrodurek, thank you for your quick response. The Resources type is like: export = LocaleResource;
declare const LocaleResource: {
ns1: {
key1: string;
key2: string;
key3: string;
// ... I have 48 namespaces. And there are just loads of keys under every namespaces, no array or object. Actually I’ve already reproduced the error on CodeSandbox. |
Type instantiation is excessively deep and possibly infinite
when the keys are to muchType instantiation is excessively deep and possibly infinite
when there are loads of keys
Hey @jigsawye, thanks for your help. The bug isn't related to the number of keys, but more with the number of namespaces. It seems to be a typescript limitation/bug. We can see on the examples below, that with 22 namespaces it doesn't throw any error, but from 23 it does. The type is inferred properly and there are no compilation time issues though, it's just a warning. They have an opened issue regarding that, and I posted my examples there. While they investigate it, I'll try to find a way to handle that on our end. All help is welcome! I'll keep you posted. Unfortunately, typescript doesn't provide a way to suppress this warning via tsconfig (only via |
Hey @jigsawye, can you check if you're still getting the warning on the version 11.8.4? |
@pedrodurek Thanks for your help. The type checking works fine now! But I have another question. Please have a look thanks 😄 |
Hi @jigsawye, I'm glad to hear that! |
@pedrodurek Sure! 😄 |
To add to this, you must import your translation files: Requiring any of them will trigger the error as well: |
I had this error while using namespaces (as in Typescript section in docs) - I had a typo in |
I'm still having this weird error, and it weirdly doesn't happen all the time, only for a specific case (not even use), and I don't have so many namespaces like mentioned previously, or I'm using namespace prefixes either, look out this example below: any help would be awesome ps.: I'm using the namespace in |
Hey @renatobenks, it may be a wrong configuration, could you share an example on codesandbox? |
Hey, I am having a similar issue in VS Code using Typescript version import React from 'react';
import { useTranslation } from 'react-i18next';
const TestComponent = () => {
const { t } = useTranslation(); // error occurs when trying to use useTranslation()
return <>{t('test')}</>;
}; I am using |
Hey @jonguenther, I don't see any error on the link you provided (codesandbox) |
@pedrodurek thanks for the reply, turns out I had a misconfiguration of |
An empty array in the translations file caused the error for me:
Populating the array fixed the issue for me |
I'am having the same issue with
I am using "react-i18next": "^11.18.0" |
🐛 Bug Report
I have a locale resource which has over than 2500 keys.
After I followed #1193 to set correct types of my project, the errors just happened.
To Reproduce
Expected behavior
No errors
Your Environment
The text was updated successfully, but these errors were encountered: