Skip to content

Commit ac2a287

Browse files
committed
Middle ground
1 parent 27bfcca commit ac2a287

2 files changed

Lines changed: 87 additions & 37 deletions

File tree

src/lib/es2025.intl.d.ts

Lines changed: 79 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,56 @@
11
/// <reference lib="es2018.intl" />
22

33
declare 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
}

tests/baselines/reference/intlDurationFormat.types

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
new Intl.DurationFormat('en').format({
55
>new Intl.DurationFormat('en').format({ years: 1, hours: 20, minutes: 15, seconds: 35}) : string
66
> : ^^^^^^
7-
>new Intl.DurationFormat('en').format : (duration: Partial<Record<"years" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds" | "milliseconds" | "microseconds" | "nanoseconds", number>>) => string
8-
> : ^ ^^ ^^^^^
7+
>new Intl.DurationFormat('en').format : (duration: Partial<Record<Intl.DurationFormatUnit, number>>) => string
8+
> : ^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^
99
>new Intl.DurationFormat('en') : Intl.DurationFormat
1010
> : ^^^^^^^^^^^^^^^^^^^
11-
>Intl.DurationFormat : { new (locales?: Intl.LocalesArgument, options?: Intl.DurationFormatOptions): Intl.DurationFormat; prototype: Intl.DurationFormat; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: Pick<Intl.DurationFormatOptions, "localeMatcher">): Intl.UnicodeBCP47LocaleIdentifier[]; }
12-
> : ^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
11+
>Intl.DurationFormat : { new (locales?: Intl.LocalesArgument, options?: Intl.DurationFormatOptions): Intl.DurationFormat; prototype: Intl.DurationFormat; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.DurationFormatLocaleMatcher; }): Intl.UnicodeBCP47LocaleIdentifier[]; }
12+
> : ^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
1313
>Intl : typeof Intl
1414
> : ^^^^^^^^^^^
15-
>DurationFormat : { new (locales?: Intl.LocalesArgument, options?: Intl.DurationFormatOptions): Intl.DurationFormat; prototype: Intl.DurationFormat; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: Pick<Intl.DurationFormatOptions, "localeMatcher">): Intl.UnicodeBCP47LocaleIdentifier[]; }
16-
> : ^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
15+
>DurationFormat : { new (locales?: Intl.LocalesArgument, options?: Intl.DurationFormatOptions): Intl.DurationFormat; prototype: Intl.DurationFormat; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.DurationFormatLocaleMatcher; }): Intl.UnicodeBCP47LocaleIdentifier[]; }
16+
> : ^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
1717
>'en' : "en"
1818
> : ^^^^
19-
>format : (duration: Partial<Record<"years" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds" | "milliseconds" | "microseconds" | "nanoseconds", number>>) => string
20-
> : ^ ^^ ^^^^^
19+
>format : (duration: Partial<Record<Intl.DurationFormatUnit, number>>) => string
20+
> : ^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^
2121
>{ years: 1, hours: 20, minutes: 15, seconds: 35} : { years: number; hours: number; minutes: number; seconds: number; }
2222
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2323

0 commit comments

Comments
 (0)