11declare namespace Intl {
2-
32 /**
43 * [Unicode BCP 47 Locale Identifiers](https://unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers) definition.
54 *
@@ -16,15 +15,22 @@ declare namespace Intl {
1615 * [Specification](https://tc39.es/ecma402/#sec-singularrelativetimeunit).
1716 */
1817 type RelativeTimeFormatUnit =
19- | "year" | "years"
20- | "quarter" | "quarters"
21- | "month" | "months"
22- | "week" | "weeks"
23- | "day" | "days"
24- | "hour" | "hours"
25- | "minute" | "minutes"
26- | "second" | "seconds"
27- ;
18+ | "year"
19+ | "years"
20+ | "quarter"
21+ | "quarters"
22+ | "month"
23+ | "months"
24+ | "week"
25+ | "weeks"
26+ | "day"
27+ | "days"
28+ | "hour"
29+ | "hours"
30+ | "minute"
31+ | "minutes"
32+ | "second"
33+ | "seconds" ;
2834
2935 /**
3036 * The locale matching algorithm to use.
@@ -127,10 +133,7 @@ declare namespace Intl {
127133 *
128134 * [Specification](https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.prototype.format).
129135 */
130- format (
131- value : number ,
132- unit : RelativeTimeFormatUnit ,
133- ) : string ;
136+ format ( value : number , unit : RelativeTimeFormatUnit ) : string ;
134137
135138 /**
136139 * A version of the format method which it returns an array of objects
@@ -162,7 +165,7 @@ declare namespace Intl {
162165 */
163166 formatToParts (
164167 value : number ,
165- unit : RelativeTimeFormatUnit ,
168+ unit : RelativeTimeFormatUnit
166169 ) : RelativeTimeFormatPart [ ] ;
167170
168171 /**
@@ -219,9 +222,11 @@ declare namespace Intl {
219222 *
220223 * [Specification](https://tc39.es/ecma402/#sec-intl-relativetimeformat-constructor).
221224 */
222- new (
223- locales ?: UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier [ ] ,
224- options ?: RelativeTimeFormatOptions ,
225+ new (
226+ locales ?:
227+ | UnicodeBCP47LocaleIdentifier
228+ | UnicodeBCP47LocaleIdentifier [ ] ,
229+ options ?: RelativeTimeFormatOptions
225230 ) : RelativeTimeFormat ;
226231
227232 /**
@@ -256,34 +261,80 @@ declare namespace Intl {
256261 * [Specification](https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.supportedLocalesOf).
257262 */
258263 supportedLocalesOf (
259- locales ?: UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier [ ] ,
260- options ?: RelativeTimeFormatOptions ,
264+ locales ?:
265+ | UnicodeBCP47LocaleIdentifier
266+ | UnicodeBCP47LocaleIdentifier [ ] ,
267+ options ?: RelativeTimeFormatOptions
261268 ) : UnicodeBCP47LocaleIdentifier [ ] ;
262269 } ;
263270
271+ /**
272+ * List of sanctioned unit: https://402.ecma-international.org/7.0/#table-sanctioned-simple-unit-identifiers
273+ */
274+ type NumberFormatUnit =
275+ | "degree"
276+ | "acre"
277+ | "hectare"
278+ | "percent"
279+ | "bit"
280+ | "byte"
281+ | "gigabit"
282+ | "gigabyte"
283+ | "kilobit"
284+ | "kilobyte"
285+ | "megabit"
286+ | "megabyte"
287+ | "petabyte"
288+ | "terabit"
289+ | "terabyte"
290+ | "day"
291+ | "hour"
292+ | "millisecond"
293+ | "minute"
294+ | "month"
295+ | "second"
296+ | "week"
297+ | "year"
298+ | "centimeter"
299+ | "foot"
300+ | "inch"
301+ | "kilometer"
302+ | "meter"
303+ | "mile-scandinavian"
304+ | "mile"
305+ | "millimeter"
306+ | "yard"
307+ | "gram"
308+ | "kilogram"
309+ | "ounce"
310+ | "pound"
311+ | "stone"
312+ | "celsius"
313+ | "fahrenheit"
314+ | "fluid-ounce"
315+ | "gallon"
316+ | "liter"
317+ | "milliliter" ;
318+
264319 interface NumberFormatOptions {
265- compactDisplay ?: string ;
266- notation ?: string ;
267- signDisplay ?: string ;
268- unit ?: string ;
269- unitDisplay ?: string ;
320+ compactDisplay ?: "short" | "long" ;
321+ notation ?: "standard" | "scientific" | "engineering" | "compact" ;
322+ signDisplay ?: "auto" | "never" | "always" ;
323+ unit ?: NumberFormatUnit ;
324+ unitDisplay ?: "short" | "long" | "narrow" ;
270325 }
271326
272327 interface ResolvedNumberFormatOptions {
273- compactDisplay ?: string ;
274- notation ?: string ;
275- signDisplay ?: string ;
276- unit ?: string ;
277- unitDisplay ?: string ;
328+ compactDisplay ?: "short" | "long" ;
329+ notation ?: "standard" | "scientific" | "engineering" | "compact" ;
330+ signDisplay ?: "auto" | "never" | "always" ;
331+ unit ?: NumberFormatUnit ;
332+ unitDisplay ?: "short" | "long" | "narrow" ;
278333 }
279334
280335 interface DateTimeFormatOptions {
281- dateStyle ?: "full" | "long" | "medium" | "short" ;
282- timeStyle ?: "full" | "long" | "medium" | "short" ;
283336 calendar ?: string ;
284- dayPeriod ?: "narrow" | "short" | "long" ;
285337 numberingSystem ?: string ;
286338 hourCycle ?: "h11" | "h12" | "h23" | "h24" ;
287- fractionalSecondDigits ?: 0 | 1 | 2 | 3 ;
288339 }
289340}
0 commit comments