lib Update Request
Various Intl-related constructors and methods reject Intl.Locale objects in their locales parameter.
Related to #47802 (Signature for toLocale[X]String is missing Intl.Locale), but the updated signature is still missing for various other Intl-related constructors and methods.
Draft fix here:
main...lionel-rowe:TypeScript:fix/locales-argument
I can submit as a PR once this issue is accepted, or happy for someone else to pick it up otherwise.
Configuration Check
My compilation target is ES2022 and my lib is the default.
Missing/Incorrect Definition
Various, including but not limited to:
String#toLocaleUpperCase
Intl.Collator constructor
Intl.DateTimeFormat constructor
Intl.ListFormat constructor
Intl.Segmenter constructor
Sample Code
const locale = new Intl.Locale('es')
// these now work as expected, thanks to https://github.com/microsoft/TypeScript/pull/47811
0 .toLocaleString(locale)
new Date(0).toLocaleDateString(locale)
// ...but these all give `Argument of type 'Locale' is not assignable to parameter of type 'string | string[] | undefined'.`
// All function as expected without throwing in JS (browser/node/deno)
'x'.toLocaleUpperCase(locale)
new Intl.Collator(locale)
new Intl.DateTimeFormat(locale)
new Intl.ListFormat(locale)
new Intl.Segmenter(locale, { granularity: 'word' })
Documentation Link
https://tc39.es/ecma402/#sec-canonicalizelocalelist
CanonicalizeLocaleList is called on all such locales arguments, iterating through them as an array, checking for the [[InitializedLocale]] internal slot (used to identify Intl.Locale objects), and reading the [[Locale]] internal slot if it exists (for Intl.Locale objects, this is the string representation of the locale). Thus 'x'.toLocaleUpperCase('es') behaves identically to 'x'.toLocaleUpperCase(new Locale('es'))
🔎 Search Terms
- locales
Intl.Locale
LocalesArgument
CanonicalizeLocaleList
lib Update Request
Various
Intl-related constructors and methods rejectIntl.Localeobjects in theirlocalesparameter.Related to #47802 (Signature for
toLocale[X]Stringis missingIntl.Locale), but the updated signature is still missing for various otherIntl-related constructors and methods.Draft fix here:
main...lionel-rowe:TypeScript:fix/locales-argument
I can submit as a PR once this issue is accepted, or happy for someone else to pick it up otherwise.
Configuration Check
My compilation target is
ES2022and my lib isthe default.Missing/Incorrect Definition
Various, including but not limited to:
String#toLocaleUpperCaseIntl.CollatorconstructorIntl.DateTimeFormatconstructorIntl.ListFormatconstructorIntl.SegmenterconstructorSample Code
Documentation Link
https://tc39.es/ecma402/#sec-canonicalizelocalelist
CanonicalizeLocaleListis called on all suchlocalesarguments, iterating through them as an array, checking for the[[InitializedLocale]]internal slot (used to identifyIntl.Localeobjects), and reading the[[Locale]]internal slot if it exists (forIntl.Localeobjects, this is the string representation of the locale). Thus'x'.toLocaleUpperCase('es')behaves identically to'x'.toLocaleUpperCase(new Locale('es'))🔎 Search Terms
Intl.LocaleLocalesArgumentCanonicalizeLocaleList