Intl.DisplayNames
options object type needs to be split
#48218
Labels
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
Milestone
Bug Report
🔎 Search Terms
DisplayNames, Intl, locale
🕗 Version & Regression Information
The behaviour was altered in TypeScript 4.6.2, but it was differently incorrect prior to that:
locale
#46845, resulted in fix(46845): Add missing "locale" field to Intl.DisplayNamesOptions #46849, merged 3rd Jan -> 4.6⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Type errors in the above code for valid patterns, no type errors for invalid patterns.
🙂 Expected behavior
Only valid type errors, accurate representation of the API
Notes
The
DisplayNamesOptions
interface
:TypeScript/src/lib/es2020.intl.d.ts
Lines 294 to 300 in a4f5555
...is currently shared by
Intl.DisplayNames()
constructor, andIntl.DisplayNames.prototype.resolvedOptions()
. While the underlying objects share several properties, they are not a perfect match as the types suggest.Per MDN:
Intl.DisplayNames()
constructor should accept an object with (Partial<>
):localeMatcher
style
type
languageDisplay
fallback
Intl.DisplayNames.prototype.resolvedOptions()
should return an object with:locale
style
type
fallback
ECMA-402 links:
Intl.DisplayNames()
constructorIntl.DisplayNames.prototype.resolvedOptions()
Shoutout to @mkubilayk who spotted this during our TypeScript update!
Suggested Fix
These types are not compatible, suggesting they should be split into something like (bikeshed)
DisplayNamesOptions
andDisplayNamesResolvedOptions
.Probably a Good First Issue™
The text was updated successfully, but these errors were encountered: