Skip to content

Make Intl locales arrays readonly #56513

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

Closed
Shraymonks opened this issue Nov 22, 2023 · 0 comments · Fixed by #56621
Closed

Make Intl locales arrays readonly #56513

Shraymonks opened this issue Nov 22, 2023 · 0 comments · Fixed by #56621
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Good First Issue Well scoped, documented and has the green light Help Wanted You can do this
Milestone

Comments

@Shraymonks
Copy link

⚙ Compilation target

Any

⚙ Library

intl.d.ts

Missing / Incorrect Definition

The locales array should be typed as a readonly array in Intl constructors and methods.

Currently they typed as normal arrays which causes a type error when passing a readonly array such as navigator.languages.

Resulting in the following:
Argument of type 'readonly string[]' is not assignable to parameter of type 'string | string[] | undefined'. The type 'readonly string[]' is 'readonly' and cannot be assigned to the mutable type 'string[]'.(2345)

There was a previous PR #50135 that fixed it for one particular call site. However there are still several instances that also have this issue:

function getCanonicalLocales(locale?: string | string[]): string[];

new (locales?: string | string[], options?: PluralRulesOptions): PluralRules;
(locales?: string | string[], options?: PluralRulesOptions): PluralRules;
supportedLocalesOf(locales: string | string[], options?: { localeMatcher?: "lookup" | "best fit"; }): string[];

locales?: UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier[],

locales?: UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier[],

new (locales?: BCP47LanguageTag | BCP47LanguageTag[], options?: ListFormatOptions): ListFormat;

supportedLocalesOf(locales: BCP47LanguageTag | BCP47LanguageTag[], options?: Pick<ListFormatOptions, "localeMatcher">): BCP47LanguageTag[];

new (locales?: BCP47LanguageTag | BCP47LanguageTag[], options?: SegmenterOptions): Segmenter;

supportedLocalesOf(locales: BCP47LanguageTag | BCP47LanguageTag[], options?: Pick<SegmenterOptions, "localeMatcher">): BCP47LanguageTag[];

Sample Code

new Intl.DateTimeFormat(navigator.languages)

Documentation Link

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#using_the_browsers_preferred_language

@andrewbranch andrewbranch added Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this Good First Issue Well scoped, documented and has the green light labels Nov 27, 2023
@andrewbranch andrewbranch added this to the Backlog milestone Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Good First Issue Well scoped, documented and has the green light Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants