Skip to content

Commit 3910d9e

Browse files
authored
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
1 parent 4d1dfab commit 3910d9e

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/lib/es2020.intl.d.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
declare namespace Intl {
22

33
/**
4-
* [BCP 47 language tag](http://tools.ietf.org/html/rfc5646) definition.
4+
* [Unicode BCP 47 Locale Identifiers](https://unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers) definition.
55
*
66
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument).
77
*
8-
* [Wikipedia](https://en.wikipedia.org/wiki/IETF_language_tag).
98
*/
10-
type BCP47LanguageTag = string;
9+
type UnicodeBCP47LocaleIdentifier = string;
1110

1211
/**
1312
* Unit to use in the relative time internationalized message.
@@ -311,7 +310,7 @@ declare namespace Intl {
311310
* [Specification](https://tc39.es/ecma402/#table-relativetimeformat-resolvedoptions-properties)
312311
*/
313312
interface ResolvedRelativeTimeFormatOptions {
314-
locale: BCP47LanguageTag;
313+
locale: UnicodeBCP47LocaleIdentifier;
315314
style: RelativeTimeFormatStyle;
316315
numeric: RelativeTimeFormatNumeric;
317316
numberingSystem: string;
@@ -454,7 +453,7 @@ declare namespace Intl {
454453
* [Specification](https://tc39.es/ecma402/#sec-intl-relativetimeformat-constructor).
455454
*/
456455
new(
457-
locales?: BCP47LanguageTag | BCP47LanguageTag[],
456+
locales?: UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier[],
458457
options?: RelativeTimeFormatOptions,
459458
): RelativeTimeFormat;
460459

@@ -490,9 +489,9 @@ declare namespace Intl {
490489
* [Specification](https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.supportedLocalesOf).
491490
*/
492491
supportedLocalesOf(
493-
locales: BCP47LanguageTag | BCP47LanguageTag[],
492+
locales?: UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier[],
494493
options?: RelativeTimeFormatOptions,
495-
): BCP47LanguageTag[];
494+
): UnicodeBCP47LocaleIdentifier[];
496495
};
497496

498497
interface NumberFormatOptions {

0 commit comments

Comments
 (0)