Skip to content

Commit a4f4583

Browse files
committed
fix: revamp es2020.intl.d.ts
- Remove `fractionalSecondDigits`, `dateStyle`, `timeStyle`, `dayPeriod` since they're in ES2021 draft, not ES2020. - Clarify NumberFormatOptions, add list of sanctioned unit
1 parent 5c5d374 commit a4f4583

File tree

1 file changed

+85
-34
lines changed

1 file changed

+85
-34
lines changed

src/lib/es2020.intl.d.ts

Lines changed: 85 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
declare 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+
| "acre"
276+
| "bit"
277+
| "byte"
278+
| "celsius"
279+
| "centimeter"
280+
| "day"
281+
| "degree"
282+
| "fahrenheit"
283+
| "fluid-ounce"
284+
| "foot"
285+
| "gallon"
286+
| "gigabit"
287+
| "gigabyte"
288+
| "gram"
289+
| "hectare"
290+
| "hour"
291+
| "inch"
292+
| "kilobit"
293+
| "kilobyte"
294+
| "kilogram"
295+
| "kilometer"
296+
| "liter"
297+
| "megabit"
298+
| "megabyte"
299+
| "meter"
300+
| "mile-scandinavian"
301+
| "mile"
302+
| "milliliter"
303+
| "millimeter"
304+
| "millisecond"
305+
| "minute"
306+
| "month"
307+
| "ounce"
308+
| "percent"
309+
| "petabyte"
310+
| "pound"
311+
| "second"
312+
| "stone"
313+
| "terabit"
314+
| "terabyte"
315+
| "week"
316+
| "yard"
317+
| "year";
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

Comments
 (0)