Update Intl.DisplayNames types for better spec compliance #48442
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Following up on issue #48218 (to avoid creating too many issues about the same topic) and based on the work from pr #48262 , here are some additional updates to keep
Intl.DisplayNames
up-to-date with the spec:ResolvedDisplayNamesOptions.type
should be the same type asDisplayNamesOptions.type
, because DisplayName's internal type property simply gets mapped toresolvedOptions().type
.DisplayNamesOptions.languageDisplay
,resolvedOptions()
can also have the propertylanguageDisplay
, but only whenDisplayNamesOptions.type
is of typelanguage
.Intl.DisplayNames(locales, options)
constructor requires bothlocales
andoptions.type
, althoughlocales
can be undefined.locales
param inIntl.DisplayNames(locales, options)
andIntl.DisplayNames.supportedLocalesOf(locales)
is the sameLocalesArgument
type used across other functions fromIntl
. Additionally,LocalesArgument
doesn't strictly need to be an array of solely strings or an array of solely Locale(s), it can be an array containing both.locales
argument are defined to be processed with this same operation.locales
,options
, andoptions.localeMatcher
are optional inIntl.DisplayNames.supportedLocalesOf(locales, options)
.These behaviors have been verified with the js code below, which should execute without issue (lines meant to recreate a
TypeError
have been commented, and can be uncommented for testing):The code above should behave as expected on modern browsers, tested on Chrome(99.0.4844.84) and Firefox(98.0.2). The only caveat is that
"calendar"
,"dateTimeField"
, andlanguageDisplay
are features introduced ines2022
from this proposal, so those are currently not working in the latest NodeJs LTS v16.14.2, but should work in later versions (currently working on v17.8.0).