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

Global t does not handle arrays as defaultNS well #2118

Closed
EvertEt opened this issue Jan 18, 2024 · 3 comments · Fixed by #2121
Closed

Global t does not handle arrays as defaultNS well #2118

EvertEt opened this issue Jan 18, 2024 · 3 comments · Fixed by #2121

Comments

@EvertEt
Copy link
Contributor

EvertEt commented Jan 18, 2024

🐛 Bug Report

When setting the typescript types through CustomTypeOptions, defaultNS: ['custom']; breaks the type of i18next.t.

To Reproduce

In test/typescript/custom-types, change i18next.d.ts defaultNS: 'custom'; to defaultNS: ['custom']; which should be equivalent (for i18next-react useTranslation.t, it is working)
(Can be found in https://github.com/EvertEt/i18next/tree/error-poc)

Expected behavior

The type/function should work as before (with one or more defaultNS)

Your Environment

  • runtime version: Node 20
  • i18next version: 23.6.0
  • os: Mac

Note

I wonder if
t: TFunction<[DefaultNamespace, ...Exclude<FlatNamespace, DefaultNamespace>[]]>;
should become
t: TFunction<[$FirstNamespace<DefaultNamespace>, ...Exclude<FlatNamespace, $FirstNamespace <DefaultNamespace>>[]]>;
but that might be too simplistic.
The above can be found in https://github.com/EvertEt/i18next/tree/type-fix

@adrai
Copy link
Member

adrai commented Jan 18, 2024

Can you create a PR...
@marcalexiei can you review this?

@EvertEt EvertEt mentioned this issue Jan 18, 2024
7 tasks
@EvertEt
Copy link
Contributor Author

EvertEt commented Jan 18, 2024

I don't have enough time and knowledge to understand why the tests are failing with the above fix, sadly. I've opened a draft.

marcalexiei added a commit to marcalexiei/i18next that referenced this issue Jan 19, 2024
marcalexiei added a commit to marcalexiei/i18next that referenced this issue Jan 19, 2024
adrai pushed a commit that referenced this issue Jan 20, 2024
* types: fix support for defaultNS as array (fixes #2118)

* test: dedupe namespace types between custom-types tests

* tests: update ts test instructions
@EvertEt
Copy link
Contributor Author

EvertEt commented Jan 20, 2024

Thanks @adrai and @marcalexiei for the quick fix! We appreciate it.

I've opened a small enhancement to the fix in #2123 for our specific usage.

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