From 3910d9ede25dc67edea18406cff3d1667a52b091 Mon Sep 17 00:00:00 2001 From: Long Ho Date: Tue, 16 Feb 2021 18:56:56 -0500 Subject: [PATCH] fix: fix RelativeTimeFormat type definition (#39661) * fix: fix RelativeTimeFormat type definition Changes: 1. Change BCP47LanguageTag to UnicodeBCP47LocaleIdentifier: Those mean 2 different things. BCP47LangTag allows _ as separator while UTS35 doesn't. It also allows grandfathered locales and UTS35 doesn't. 2. Combine RelativeTimeFormat interface and const declaration into a single class. The old way of declaring as `interface` & `const` permits calling `Intl.RelativeTimeFormat` without `new` which is no longer possible after `Intl.DateTimeFormat` & `Intl.NumberFormat`. The spec explicitly forbids it in http://ecma-international.org/ecma-402/7.0/index.html#relativetimeformat-objects where: > If NewTarget is undefined, throw a TypeError exception. Intl.RelativeTimeFormat is also extensible per spec. This is closer to a `class` than the current declaration. * address feedbacks --- src/lib/es2020.intl.d.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/lib/es2020.intl.d.ts b/src/lib/es2020.intl.d.ts index 0db148085d5..53c24de478c 100644 --- a/src/lib/es2020.intl.d.ts +++ b/src/lib/es2020.intl.d.ts @@ -1,13 +1,12 @@ declare namespace Intl { /** - * [BCP 47 language tag](http://tools.ietf.org/html/rfc5646) definition. + * [Unicode BCP 47 Locale Identifiers](https://unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers) definition. * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument). * - * [Wikipedia](https://en.wikipedia.org/wiki/IETF_language_tag). */ - type BCP47LanguageTag = string; + type UnicodeBCP47LocaleIdentifier = string; /** * Unit to use in the relative time internationalized message. @@ -311,7 +310,7 @@ declare namespace Intl { * [Specification](https://tc39.es/ecma402/#table-relativetimeformat-resolvedoptions-properties) */ interface ResolvedRelativeTimeFormatOptions { - locale: BCP47LanguageTag; + locale: UnicodeBCP47LocaleIdentifier; style: RelativeTimeFormatStyle; numeric: RelativeTimeFormatNumeric; numberingSystem: string; @@ -454,7 +453,7 @@ declare namespace Intl { * [Specification](https://tc39.es/ecma402/#sec-intl-relativetimeformat-constructor). */ new( - locales?: BCP47LanguageTag | BCP47LanguageTag[], + locales?: UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier[], options?: RelativeTimeFormatOptions, ): RelativeTimeFormat; @@ -490,9 +489,9 @@ declare namespace Intl { * [Specification](https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.supportedLocalesOf). */ supportedLocalesOf( - locales: BCP47LanguageTag | BCP47LanguageTag[], + locales?: UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier[], options?: RelativeTimeFormatOptions, - ): BCP47LanguageTag[]; + ): UnicodeBCP47LocaleIdentifier[]; }; interface NumberFormatOptions {