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

types: support readonly defaultNS #2123

Merged
merged 1 commit into from
Jan 20, 2024

Conversation

EvertEt
Copy link
Contributor

@EvertEt EvertEt commented Jan 20, 2024

Follow-up of #2121 to also allow defaultNS to be readonly (This is the case when using as const on the defaultNS definitions and using typeof defaultNS in the types)

Checklist

  • only relevant code is changed (make a diff before you submit the PR)
  • run tests npm run test
  • tests are included
  • commit message and code follows the Developer's Certification of Origin

Checklist (for documentation change)

  • only relevant documentation part is changed (make a diff before you submit the PR)
  • motivation/reason is provided
  • commit message and code follows the Developer's Certification of Origin

@adrai
Copy link
Member

adrai commented Jan 20, 2024

is this ok @marcalexiei ?

@coveralls
Copy link

Coverage Status

coverage: 96.239%. remained the same
when pulling 10def45 on EvertEt:fix-readonly-defaultns
into 56b19b3 on i18next:master.

@@ -12,4 +12,4 @@ export type $OmitArrayKeys<Arr> = Arr extends readonly any[] ? Omit<Arr, keyof a

export type $PreservedValue<Value, Fallback> = [Value] extends [never] ? Fallback : Value;

export type $NormalizeIntoArray<T extends unknown | unknown[]> = T extends unknown[] ? T : [T];
export type $NormalizeIntoArray<T extends unknown | readonly unknown[]> = T extends readonly unknown[] ? T : [T];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this fix when using a normal array as defaultNS the types won't work.
You can try out removing Readonly<...> from the `CustomTypeOptions.defaultNS.

You have to take into account both array types.

This should do the trick:

Suggested change
export type $NormalizeIntoArray<T extends unknown | readonly unknown[]> = T extends readonly unknown[] ? T : [T];
export type $NormalizeIntoArray<T extends unknown | readonly unknown[] | unknown[]> = T extends
| unknown[]
| readonly unknown[]
? T
: [T];

Copy link
Contributor Author

@EvertEt EvertEt Jan 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, sorry.
I tested this on my local branch but probably I had something on my working copy that broke the test 😅

@marcalexiei
Copy link
Member

@adrai LGTM

@adrai adrai merged commit 063b5fa into i18next:master Jan 20, 2024
6 of 7 checks passed
@adrai
Copy link
Member

adrai commented Jan 20, 2024

thank you both...
it's included in v23.7.18

@EvertEt EvertEt deleted the fix-readonly-defaultns branch January 21, 2024 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants