Skip to content

Commit b8b1201

Browse files
islandryusandersn
andauthoredFeb 17, 2022
fix(47024):fix type of DateTimeFormat and NumberFormat (#47117)
* fix type of DateTimeFormat and NumberFormat * add NumberFormat to esnext.intl.d.ts * Update src/lib/esnext.intl.d.ts Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> * better unification of previous changes Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
1 parent 51d3446 commit b8b1201

18 files changed

+179
-42
lines changed
 

‎src/lib/es2021.intl.d.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ declare namespace Intl {
88
fractionalSecondDigits?: 0 | 1 | 2 | 3 | undefined;
99
}
1010

11+
interface DateTimeFormat {
12+
formatRange(startDate: Date | number | bigint, endDate: Date | number | bigint): string;
13+
formatRangeToParts(startDate: Date | number | bigint, endDate: Date | number | bigint): DateTimeFormatPart[];
14+
}
15+
1116
interface ResolvedDateTimeFormatOptions {
1217
formatMatcher?: "basic" | "best fit" | "best fit";
1318
dateStyle?: "full" | "long" | "medium" | "short";
@@ -16,9 +21,4 @@ declare namespace Intl {
1621
dayPeriod?: "narrow" | "short" | "long";
1722
fractionalSecondDigits?: 0 | 1 | 2 | 3;
1823
}
19-
20-
interface NumberFormat {
21-
formatRange(startDate: number | bigint, endDate: number | bigint): string;
22-
formatRangeToParts(startDate: number | bigint, endDate: number | bigint): NumberFormatPart[];
23-
}
24-
}
24+
}

‎src/lib/es5.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4385,6 +4385,7 @@ declare namespace Intl {
43854385
new(locales?: string | string[], options?: NumberFormatOptions): NumberFormat;
43864386
(locales?: string | string[], options?: NumberFormatOptions): NumberFormat;
43874387
supportedLocalesOf(locales: string | string[], options?: NumberFormatOptions): string[];
4388+
readonly prototype: NumberFormat;
43884389
};
43894390

43904391
interface DateTimeFormatOptions {
@@ -4428,6 +4429,7 @@ declare namespace Intl {
44284429
new(locales?: string | string[], options?: DateTimeFormatOptions): DateTimeFormat;
44294430
(locales?: string | string[], options?: DateTimeFormatOptions): DateTimeFormat;
44304431
supportedLocalesOf(locales: string | string[], options?: DateTimeFormatOptions): string[];
4432+
readonly prototype: DateTimeFormat;
44314433
};
44324434
}
44334435

‎src/lib/esnext.intl.d.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
declare namespace Intl {
2-
3-
interface DateTimeFormat {
4-
formatRange(startName: Date, endNumber: Date): string;
5-
}
2+
interface NumberFormat {
3+
formatRange(start: number | bigint, end: number | bigint): string;
4+
formatRangeToParts(start: number | bigint, end: number | bigint): NumberFormatPart[];
5+
}
66
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
tests/cases/compiler/DateTimeFormatAndNumberFormatES2021.ts(1,29): error TS2339: Property 'formatRange' does not exist on type 'NumberFormat'.
2+
tests/cases/compiler/DateTimeFormatAndNumberFormatES2021.ts(4,25): error TS2339: Property 'formatRange' does not exist on type 'NumberFormat'.
3+
tests/cases/compiler/DateTimeFormatAndNumberFormatES2021.ts(5,25): error TS2339: Property 'formatRangeToParts' does not exist on type 'NumberFormat'.
4+
5+
6+
==== tests/cases/compiler/DateTimeFormatAndNumberFormatES2021.ts (3 errors) ====
7+
Intl.NumberFormat.prototype.formatRange
8+
~~~~~~~~~~~
9+
!!! error TS2339: Property 'formatRange' does not exist on type 'NumberFormat'.
10+
Intl.DateTimeFormat.prototype.formatRange
11+
12+
new Intl.NumberFormat().formatRange
13+
~~~~~~~~~~~
14+
!!! error TS2339: Property 'formatRange' does not exist on type 'NumberFormat'.
15+
new Intl.NumberFormat().formatRangeToParts
16+
~~~~~~~~~~~~~~~~~~
17+
!!! error TS2339: Property 'formatRangeToParts' does not exist on type 'NumberFormat'.
18+
new Intl.DateTimeFormat().formatRange
19+
new Intl.DateTimeFormat().formatRangeToParts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [DateTimeFormatAndNumberFormatES2021.ts]
2+
Intl.NumberFormat.prototype.formatRange
3+
Intl.DateTimeFormat.prototype.formatRange
4+
5+
new Intl.NumberFormat().formatRange
6+
new Intl.NumberFormat().formatRangeToParts
7+
new Intl.DateTimeFormat().formatRange
8+
new Intl.DateTimeFormat().formatRangeToParts
9+
10+
//// [DateTimeFormatAndNumberFormatES2021.js]
11+
Intl.NumberFormat.prototype.formatRange;
12+
Intl.DateTimeFormat.prototype.formatRange;
13+
new Intl.NumberFormat().formatRange;
14+
new Intl.NumberFormat().formatRangeToParts;
15+
new Intl.DateTimeFormat().formatRange;
16+
new Intl.DateTimeFormat().formatRangeToParts;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
=== tests/cases/compiler/DateTimeFormatAndNumberFormatES2021.ts ===
2+
Intl.NumberFormat.prototype.formatRange
3+
>Intl.NumberFormat.prototype : Symbol(prototype, Decl(lib.es5.d.ts, --, --))
4+
>Intl.NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
5+
>Intl : Symbol(Intl, Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --) ... and 1 more)
6+
>NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
7+
>prototype : Symbol(prototype, Decl(lib.es5.d.ts, --, --))
8+
9+
Intl.DateTimeFormat.prototype.formatRange
10+
>Intl.DateTimeFormat.prototype.formatRange : Symbol(Intl.DateTimeFormat.formatRange, Decl(lib.es2021.intl.d.ts, --, --))
11+
>Intl.DateTimeFormat.prototype : Symbol(prototype, Decl(lib.es5.d.ts, --, --))
12+
>Intl.DateTimeFormat : Symbol(Intl.DateTimeFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2021.intl.d.ts, --, --))
13+
>Intl : Symbol(Intl, Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --) ... and 1 more)
14+
>DateTimeFormat : Symbol(Intl.DateTimeFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2021.intl.d.ts, --, --))
15+
>prototype : Symbol(prototype, Decl(lib.es5.d.ts, --, --))
16+
>formatRange : Symbol(Intl.DateTimeFormat.formatRange, Decl(lib.es2021.intl.d.ts, --, --))
17+
18+
new Intl.NumberFormat().formatRange
19+
>Intl.NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
20+
>Intl : Symbol(Intl, Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --) ... and 1 more)
21+
>NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
22+
23+
new Intl.NumberFormat().formatRangeToParts
24+
>Intl.NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
25+
>Intl : Symbol(Intl, Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --) ... and 1 more)
26+
>NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
27+
28+
new Intl.DateTimeFormat().formatRange
29+
>new Intl.DateTimeFormat().formatRange : Symbol(Intl.DateTimeFormat.formatRange, Decl(lib.es2021.intl.d.ts, --, --))
30+
>Intl.DateTimeFormat : Symbol(Intl.DateTimeFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2021.intl.d.ts, --, --))
31+
>Intl : Symbol(Intl, Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --) ... and 1 more)
32+
>DateTimeFormat : Symbol(Intl.DateTimeFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2021.intl.d.ts, --, --))
33+
>formatRange : Symbol(Intl.DateTimeFormat.formatRange, Decl(lib.es2021.intl.d.ts, --, --))
34+
35+
new Intl.DateTimeFormat().formatRangeToParts
36+
>new Intl.DateTimeFormat().formatRangeToParts : Symbol(Intl.DateTimeFormat.formatRangeToParts, Decl(lib.es2021.intl.d.ts, --, --))
37+
>Intl.DateTimeFormat : Symbol(Intl.DateTimeFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2021.intl.d.ts, --, --))
38+
>Intl : Symbol(Intl, Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --) ... and 1 more)
39+
>DateTimeFormat : Symbol(Intl.DateTimeFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2021.intl.d.ts, --, --))
40+
>formatRangeToParts : Symbol(Intl.DateTimeFormat.formatRangeToParts, Decl(lib.es2021.intl.d.ts, --, --))
41+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
=== tests/cases/compiler/DateTimeFormatAndNumberFormatES2021.ts ===
2+
Intl.NumberFormat.prototype.formatRange
3+
>Intl.NumberFormat.prototype.formatRange : any
4+
>Intl.NumberFormat.prototype : Intl.NumberFormat
5+
>Intl.NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; readonly prototype: Intl.NumberFormat; }
6+
>Intl : typeof Intl
7+
>NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; readonly prototype: Intl.NumberFormat; }
8+
>prototype : Intl.NumberFormat
9+
>formatRange : any
10+
11+
Intl.DateTimeFormat.prototype.formatRange
12+
>Intl.DateTimeFormat.prototype.formatRange : (startDate: number | bigint | Date, endDate: number | bigint | Date) => string
13+
>Intl.DateTimeFormat.prototype : Intl.DateTimeFormat
14+
>Intl.DateTimeFormat : { (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; new (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; supportedLocalesOf(locales: string | string[], options?: Intl.DateTimeFormatOptions): string[]; readonly prototype: Intl.DateTimeFormat; }
15+
>Intl : typeof Intl
16+
>DateTimeFormat : { (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; new (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; supportedLocalesOf(locales: string | string[], options?: Intl.DateTimeFormatOptions): string[]; readonly prototype: Intl.DateTimeFormat; }
17+
>prototype : Intl.DateTimeFormat
18+
>formatRange : (startDate: number | bigint | Date, endDate: number | bigint | Date) => string
19+
20+
new Intl.NumberFormat().formatRange
21+
>new Intl.NumberFormat().formatRange : any
22+
>new Intl.NumberFormat() : Intl.NumberFormat
23+
>Intl.NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; readonly prototype: Intl.NumberFormat; }
24+
>Intl : typeof Intl
25+
>NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; readonly prototype: Intl.NumberFormat; }
26+
>formatRange : any
27+
28+
new Intl.NumberFormat().formatRangeToParts
29+
>new Intl.NumberFormat().formatRangeToParts : any
30+
>new Intl.NumberFormat() : Intl.NumberFormat
31+
>Intl.NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; readonly prototype: Intl.NumberFormat; }
32+
>Intl : typeof Intl
33+
>NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; readonly prototype: Intl.NumberFormat; }
34+
>formatRangeToParts : any
35+
36+
new Intl.DateTimeFormat().formatRange
37+
>new Intl.DateTimeFormat().formatRange : (startDate: number | bigint | Date, endDate: number | bigint | Date) => string
38+
>new Intl.DateTimeFormat() : Intl.DateTimeFormat
39+
>Intl.DateTimeFormat : { (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; new (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; supportedLocalesOf(locales: string | string[], options?: Intl.DateTimeFormatOptions): string[]; readonly prototype: Intl.DateTimeFormat; }
40+
>Intl : typeof Intl
41+
>DateTimeFormat : { (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; new (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; supportedLocalesOf(locales: string | string[], options?: Intl.DateTimeFormatOptions): string[]; readonly prototype: Intl.DateTimeFormat; }
42+
>formatRange : (startDate: number | bigint | Date, endDate: number | bigint | Date) => string
43+
44+
new Intl.DateTimeFormat().formatRangeToParts
45+
>new Intl.DateTimeFormat().formatRangeToParts : (startDate: number | bigint | Date, endDate: number | bigint | Date) => Intl.DateTimeFormatPart[]
46+
>new Intl.DateTimeFormat() : Intl.DateTimeFormat
47+
>Intl.DateTimeFormat : { (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; new (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; supportedLocalesOf(locales: string | string[], options?: Intl.DateTimeFormatOptions): string[]; readonly prototype: Intl.DateTimeFormat; }
48+
>Intl : typeof Intl
49+
>DateTimeFormat : { (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; new (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; supportedLocalesOf(locales: string | string[], options?: Intl.DateTimeFormatOptions): string[]; readonly prototype: Intl.DateTimeFormat; }
50+
>formatRangeToParts : (startDate: number | bigint | Date, endDate: number | bigint | Date) => Intl.DateTimeFormatPart[]
51+

‎tests/baselines/reference/bigintWithLib.types

+4-4
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,9 @@ new Intl.NumberFormat("fr").format(3000n);
390390
>new Intl.NumberFormat("fr").format(3000n) : string
391391
>new Intl.NumberFormat("fr").format : { (value: number): string; (value: number | bigint): string; }
392392
>new Intl.NumberFormat("fr") : Intl.NumberFormat
393-
>Intl.NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; }
393+
>Intl.NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; readonly prototype: Intl.NumberFormat; }
394394
>Intl : typeof Intl
395-
>NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; }
395+
>NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; readonly prototype: Intl.NumberFormat; }
396396
>"fr" : "fr"
397397
>format : { (value: number): string; (value: number | bigint): string; }
398398
>3000n : 3000n
@@ -401,9 +401,9 @@ new Intl.NumberFormat("fr").format(bigintVal);
401401
>new Intl.NumberFormat("fr").format(bigintVal) : string
402402
>new Intl.NumberFormat("fr").format : { (value: number): string; (value: number | bigint): string; }
403403
>new Intl.NumberFormat("fr") : Intl.NumberFormat
404-
>Intl.NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; }
404+
>Intl.NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; readonly prototype: Intl.NumberFormat; }
405405
>Intl : typeof Intl
406-
>NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; }
406+
>NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; readonly prototype: Intl.NumberFormat; }
407407
>"fr" : "fr"
408408
>format : { (value: number): string; (value: number | bigint): string; }
409409
>bigintVal : bigint

0 commit comments

Comments
 (0)
Please sign in to comment.