-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Description
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
constructorIntl.DateTimeFormat
constructorIntl.ListFormat
constructorIntl.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