11/// <reference lib="es2018.intl" />
22
33declare namespace Intl {
4+ /**
5+ * The locale matching algorithm to use.
6+ *
7+ * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation).
8+ */
9+ type DurationFormatLocaleMatcher = "lookup" | "best fit" ;
10+
11+ /**
12+ * The style of the formatted duration.
13+ *
14+ * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#style).
15+ */
16+ type DurationFormatStyle = "long" | "short" | "narrow" | "digital" ;
17+
18+ /**
19+ * Whether to always display a unit, or only if it is non-zero.
20+ *
21+ * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#display).
22+ */
23+ type DurationFormatDisplayOption = "always" | "auto" ;
24+
25+ /**
26+ * Value of the `unit` property in duration objects
27+ *
28+ * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format#duration).
29+ */
30+ type DurationFormatUnit =
31+ | "years"
32+ | "months"
33+ | "weeks"
34+ | "days"
35+ | "hours"
36+ | "minutes"
37+ | "seconds"
38+ | "milliseconds"
39+ | "microseconds"
40+ | "nanoseconds" ;
41+
42+ type DurationFormatUnitSingular =
43+ | "year"
44+ | "month"
45+ | "week"
46+ | "day"
47+ | "hour"
48+ | "minute"
49+ | "second"
50+ | "millisecond"
51+ | "microsecond"
52+ | "nanosecond" ;
53+
454 /**
555 * An object representing the relative time format in parts
656 * that can be used for custom locale-aware formatting.
@@ -11,12 +61,12 @@ declare namespace Intl {
1161 | {
1262 type : "literal" ;
1363 value : string ;
14- unit ?: "year" | "month" | "week" | "day" | "hour" | "minute" | "second" | "milliseconds" | "microseconds" | "nanoseconds" ;
64+ unit ?: DurationFormatUnit ;
1565 }
1666 | {
1767 type : Exclude < NumberFormatPartTypes , "literal" > ;
1868 value : string ;
19- unit : "year" | "month" | "week" | "day" | "hour" | "minute" | "second" | "milliseconds" | "microseconds" | "nanoseconds" ;
69+ unit : DurationFormatUnitSingular ;
2070 } ;
2171
2272 /**
@@ -25,29 +75,29 @@ declare namespace Intl {
2575 * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#parameters)
2676 */
2777 interface DurationFormatOptions {
28- localeMatcher ?: "lookup" | "best fit" | undefined ;
78+ localeMatcher ?: DurationFormatLocaleMatcher | undefined ;
2979 numberingSystem ?: string | undefined ;
30- style ?: "long" | "short" | "narrow" | "digital" | undefined ;
80+ style ?: DurationFormatStyle | undefined ;
3181 years ?: "long" | "short" | "narrow" | undefined ;
32- yearsDisplay ?: "always" | "auto" | undefined ;
82+ yearsDisplay ?: DurationFormatDisplayOption | undefined ;
3383 months ?: "long" | "short" | "narrow" | undefined ;
34- monthsDisplay ?: "always" | "auto" | undefined ;
84+ monthsDisplay ?: DurationFormatDisplayOption | undefined ;
3585 weeks ?: "long" | "short" | "narrow" | undefined ;
36- weeksDisplay ?: "always" | "auto" | undefined ;
86+ weeksDisplay ?: DurationFormatDisplayOption | undefined ;
3787 days ?: "long" | "short" | "narrow" | undefined ;
38- daysDisplay ?: "always" | "auto" | undefined ;
88+ daysDisplay ?: DurationFormatDisplayOption | undefined ;
3989 hours ?: "long" | "short" | "narrow" | "numeric" | "2-digit" | undefined ;
40- hoursDisplay ?: "always" | "auto" | undefined ;
90+ hoursDisplay ?: DurationFormatDisplayOption | undefined ;
4191 minutes ?: "long" | "short" | "narrow" | "numeric" | "2-digit" | undefined ;
42- minutesDisplay ?: "always" | "auto" | undefined ;
92+ minutesDisplay ?: DurationFormatDisplayOption | undefined ;
4393 seconds ?: "long" | "short" | "narrow" | "numeric" | "2-digit" | undefined ;
44- secondsDisplay ?: "always" | "auto" | undefined ;
94+ secondsDisplay ?: DurationFormatDisplayOption | undefined ;
4595 milliseconds ?: "long" | "short" | "narrow" | "numeric" | undefined ;
46- millisecondsDisplay ?: "always" | "auto" | undefined ;
96+ millisecondsDisplay ?: DurationFormatDisplayOption | undefined ;
4797 microseconds ?: "long" | "short" | "narrow" | "numeric" | undefined ;
48- microsecondsDisplay ?: "always" | "auto" | undefined ;
98+ microsecondsDisplay ?: DurationFormatDisplayOption | undefined ;
4999 nanoseconds ?: "long" | "short" | "narrow" | "numeric" | undefined ;
50- nanosecondsDisplay ?: "always" | "auto" | undefined ;
100+ nanosecondsDisplay ?: DurationFormatDisplayOption | undefined ;
51101 fractionalDigits ?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | undefined ;
52102 }
53103
@@ -62,43 +112,43 @@ declare namespace Intl {
62112 *
63113 * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format).
64114 */
65- format ( duration : Partial < Record < "years" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds" | "milliseconds" | "microseconds" | "nanoseconds" , number > > ) : string ;
115+ format ( duration : Partial < Record < DurationFormatUnit , number > > ) : string ;
66116 /**
67117 * @param duration The duration object to be formatted. It should include some or all of the following properties: months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds.
68118 *
69119 * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts).
70120 */
71- formatToParts ( duration : Partial < Record < "years" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds" | "milliseconds" | "microseconds" | "nanoseconds" , number > > ) : DurationFormatPart [ ] ;
121+ formatToParts ( duration : Partial < Record < DurationFormatUnit , number > > ) : DurationFormatPart [ ] ;
72122 /**
73123 * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions).
74124 */
75125 resolvedOptions ( ) : ResolvedDurationFormatOptions ;
76126 }
77127
78128 interface ResolvedDurationFormatOptions {
79- locale : string ;
129+ locale : UnicodeBCP47LocaleIdentifier ;
80130 numberingSystem : string ;
81- style : "long" | "short" | "narrow" | "digital" ;
131+ style : DurationFormatStyle ;
82132 years : "long" | "short" | "narrow" ;
83- yearsDisplay : "always" | "auto" ;
133+ yearsDisplay : DurationFormatDisplayOption ;
84134 months : "long" | "short" | "narrow" ;
85- monthsDisplay : "always" | "auto" ;
135+ monthsDisplay : DurationFormatDisplayOption ;
86136 weeks : "long" | "short" | "narrow" ;
87- weeksDisplay : "always" | "auto" ;
137+ weeksDisplay : DurationFormatDisplayOption ;
88138 days : "long" | "short" | "narrow" ;
89- daysDisplay : "always" | "auto" ;
139+ daysDisplay : DurationFormatDisplayOption ;
90140 hours : "long" | "short" | "narrow" | "numeric" | "2-digit" ;
91- hoursDisplay : "always" | "auto" ;
141+ hoursDisplay : DurationFormatDisplayOption ;
92142 minutes : "long" | "short" | "narrow" | "numeric" | "2-digit" ;
93- minutesDisplay : "always" | "auto" ;
143+ minutesDisplay : DurationFormatDisplayOption ;
94144 seconds : "long" | "short" | "narrow" | "numeric" | "2-digit" ;
95- secondsDisplay : "always" | "auto" ;
145+ secondsDisplay : DurationFormatDisplayOption ;
96146 milliseconds : "long" | "short" | "narrow" | "numeric" ;
97- millisecondsDisplay : "always" | "auto" ;
147+ millisecondsDisplay : DurationFormatDisplayOption ;
98148 microseconds : "long" | "short" | "narrow" | "numeric" ;
99- microsecondsDisplay : "always" | "auto" ;
149+ microsecondsDisplay : DurationFormatDisplayOption ;
100150 nanoseconds : "long" | "short" | "narrow" | "numeric" ;
101- nanosecondsDisplay : "always" | "auto" ;
151+ nanosecondsDisplay : DurationFormatDisplayOption ;
102152 fractionalDigits ?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ;
103153 }
104154
@@ -129,6 +179,6 @@ declare namespace Intl {
129179 *
130180 * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/supportedLocalesOf).
131181 */
132- supportedLocalesOf ( locales ?: LocalesArgument , options ?: Pick < DurationFormatOptions , " localeMatcher" > ) : UnicodeBCP47LocaleIdentifier [ ] ;
182+ supportedLocalesOf ( locales ?: LocalesArgument , options ?: { localeMatcher ?: DurationFormatLocaleMatcher ; } ) : UnicodeBCP47LocaleIdentifier [ ] ;
133183 } ;
134184}
0 commit comments