-
Notifications
You must be signed in to change notification settings - Fork 13k
Description
⚙ 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:
TypeScript/src/lib/es2016.intl.d.ts
Line 12 in d4fbc9b
function getCanonicalLocales(locale?: string | string[]): string[]; |
TypeScript/src/lib/es2018.intl.d.ts
Lines 33 to 36 in d4fbc9b
new (locales?: string | string[], options?: PluralRulesOptions): PluralRules; | |
(locales?: string | string[], options?: PluralRulesOptions): PluralRules; | |
supportedLocalesOf(locales: string | string[], options?: { localeMatcher?: "lookup" | "best fit"; }): string[]; |
TypeScript/src/lib/es2020.intl.d.ts
Line 203 in d4fbc9b
locales?: UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier[], |
TypeScript/src/lib/es2020.intl.d.ts
Line 226 in d4fbc9b
locales?: UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier[], |
TypeScript/src/lib/es2021.intl.d.ts
Line 128 in d4fbc9b
new (locales?: BCP47LanguageTag | BCP47LanguageTag[], options?: ListFormatOptions): ListFormat; |
TypeScript/src/lib/es2021.intl.d.ts
Line 146 in d4fbc9b
supportedLocalesOf(locales: BCP47LanguageTag | BCP47LanguageTag[], options?: Pick<ListFormatOptions, "localeMatcher">): BCP47LanguageTag[]; |
TypeScript/src/lib/es2022.intl.d.ts
Line 74 in d4fbc9b
new (locales?: BCP47LanguageTag | BCP47LanguageTag[], options?: SegmenterOptions): Segmenter; |
TypeScript/src/lib/es2022.intl.d.ts
Line 88 in d4fbc9b
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