Skip to content

fix(56513): Allow Intl locales to be readonly arrays #56621

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

Merged
merged 4 commits into from
Dec 13, 2023

Conversation

robballou
Copy link
Contributor

Fixes #56513:

Updates the definitions for Intl.getCanonicalLocales() and Intl.PluralRules constructors/methods to accept readonly arrays. Several of the locations mentioned in the issue seem to be correctly defined now (essentially >= es2020) since they build off LocalesArgument.

Updates the definitions for Intl.getCanonicalLocales() and Intl.PluralRules constructors/methods to accept readonly arrays.
@robballou
Copy link
Contributor Author

@microsoft-github-policy-service agree

@@ -9,5 +9,5 @@ declare namespace Intl {
* @param locale A list of String values for which to get the canonical locale names
* @returns An array containing the canonical and validated locale names.
*/
function getCanonicalLocales(locale?: string | string[]): string[];
function getCanonicalLocales(locale?: string | string[] | Readonly<string[]>): string[];
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be readonly string[] or ReadonlyArray<string>? (notably, the baselines print the type as string | string[] | readonly string[])

Also, the previous PR added readonly on the existing arrays. I think that's good enough here too:

Suggested change
function getCanonicalLocales(locale?: string | string[] | Readonly<string[]>): string[];
function getCanonicalLocales(locale?: string | readonly string[]): string[];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, that makes sense. I was worried about excluding non-readonly arrays but see that it doesn't behave that way (TIL). Updated.

new (locales?: string | string[], options?: PluralRulesOptions): PluralRules;
(locales?: string | string[], options?: PluralRulesOptions): PluralRules;
supportedLocalesOf(locales: string | string[], options?: { localeMatcher?: "lookup" | "best fit"; }): string[];
new (locales?: string | string[] | Readonly<string[]>, options?: PluralRulesOptions): PluralRules;
Copy link
Member

Choose a reason for hiding this comment

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

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also updated. Thank you

@sandersn sandersn merged commit 431d3e8 into microsoft:main Dec 13, 2023
c0sta pushed a commit to c0sta/TypeScript that referenced this pull request Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Make Intl locales arrays readonly
3 participants