Skip to content

fix(47024):fix type of DateTimeFormat and NumberFormat #47117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/lib/es2021.intl.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ declare namespace Intl {
fractionalSecondDigits?: 0 | 1 | 2 | 3 | undefined;
}

interface DateTimeFormat {
formatRange(startDate: Date | number | bigint, endDate: Date | number | bigint): string;
formatRangeToParts(startDate: Date | number | bigint, endDate: Date | number | bigint): DateTimeFormatPart[];
}

interface ResolvedDateTimeFormatOptions {
formatMatcher?: "basic" | "best fit" | "best fit";
dateStyle?: "full" | "long" | "medium" | "short";
Expand All @@ -16,9 +21,4 @@ declare namespace Intl {
dayPeriod?: "narrow" | "short" | "long";
fractionalSecondDigits?: 0 | 1 | 2 | 3;
}

interface NumberFormat {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you perhaps move this to esnext.intl.d.ts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review!
I've fixed it.

formatRange(startDate: number | bigint, endDate: number | bigint): string;
formatRangeToParts(startDate: number | bigint, endDate: number | bigint): NumberFormatPart[];
}
}
}
2 changes: 2 additions & 0 deletions src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4385,6 +4385,7 @@ declare namespace Intl {
new(locales?: string | string[], options?: NumberFormatOptions): NumberFormat;
(locales?: string | string[], options?: NumberFormatOptions): NumberFormat;
supportedLocalesOf(locales: string | string[], options?: NumberFormatOptions): string[];
readonly prototype: NumberFormat;
};

interface DateTimeFormatOptions {
Expand Down Expand Up @@ -4428,6 +4429,7 @@ declare namespace Intl {
new(locales?: string | string[], options?: DateTimeFormatOptions): DateTimeFormat;
(locales?: string | string[], options?: DateTimeFormatOptions): DateTimeFormat;
supportedLocalesOf(locales: string | string[], options?: DateTimeFormatOptions): string[];
readonly prototype: DateTimeFormat;
};
}

Expand Down
8 changes: 4 additions & 4 deletions src/lib/esnext.intl.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare namespace Intl {

interface DateTimeFormat {
formatRange(startName: Date, endNumber: Date): string;
}
interface NumberFormat {
formatRange(start: number | bigint, end: number | bigint): string;
formatRangeToParts(start: number | bigint, end: number | bigint): NumberFormatPart[];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
tests/cases/compiler/DateTimeFormatAndNumberFormatES2021.ts(1,29): error TS2339: Property 'formatRange' does not exist on type 'NumberFormat'.
tests/cases/compiler/DateTimeFormatAndNumberFormatES2021.ts(4,25): error TS2339: Property 'formatRange' does not exist on type 'NumberFormat'.
tests/cases/compiler/DateTimeFormatAndNumberFormatES2021.ts(5,25): error TS2339: Property 'formatRangeToParts' does not exist on type 'NumberFormat'.


==== tests/cases/compiler/DateTimeFormatAndNumberFormatES2021.ts (3 errors) ====
Intl.NumberFormat.prototype.formatRange
~~~~~~~~~~~
!!! error TS2339: Property 'formatRange' does not exist on type 'NumberFormat'.
Intl.DateTimeFormat.prototype.formatRange

new Intl.NumberFormat().formatRange
~~~~~~~~~~~
!!! error TS2339: Property 'formatRange' does not exist on type 'NumberFormat'.
new Intl.NumberFormat().formatRangeToParts
~~~~~~~~~~~~~~~~~~
!!! error TS2339: Property 'formatRangeToParts' does not exist on type 'NumberFormat'.
new Intl.DateTimeFormat().formatRange
new Intl.DateTimeFormat().formatRangeToParts
16 changes: 16 additions & 0 deletions tests/baselines/reference/DateTimeFormatAndNumberFormatES2021.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//// [DateTimeFormatAndNumberFormatES2021.ts]
Intl.NumberFormat.prototype.formatRange
Intl.DateTimeFormat.prototype.formatRange

new Intl.NumberFormat().formatRange
new Intl.NumberFormat().formatRangeToParts
new Intl.DateTimeFormat().formatRange
new Intl.DateTimeFormat().formatRangeToParts

//// [DateTimeFormatAndNumberFormatES2021.js]
Intl.NumberFormat.prototype.formatRange;
Intl.DateTimeFormat.prototype.formatRange;
new Intl.NumberFormat().formatRange;
new Intl.NumberFormat().formatRangeToParts;
new Intl.DateTimeFormat().formatRange;
new Intl.DateTimeFormat().formatRangeToParts;
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
=== tests/cases/compiler/DateTimeFormatAndNumberFormatES2021.ts ===
Intl.NumberFormat.prototype.formatRange
>Intl.NumberFormat.prototype : Symbol(prototype, Decl(lib.es5.d.ts, --, --))
>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, --, --))
>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)
>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, --, --))
>prototype : Symbol(prototype, Decl(lib.es5.d.ts, --, --))

Intl.DateTimeFormat.prototype.formatRange
>Intl.DateTimeFormat.prototype.formatRange : Symbol(Intl.DateTimeFormat.formatRange, Decl(lib.es2021.intl.d.ts, --, --))
>Intl.DateTimeFormat.prototype : Symbol(prototype, Decl(lib.es5.d.ts, --, --))
>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, --, --))
>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)
>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, --, --))
>prototype : Symbol(prototype, Decl(lib.es5.d.ts, --, --))
>formatRange : Symbol(Intl.DateTimeFormat.formatRange, Decl(lib.es2021.intl.d.ts, --, --))

new Intl.NumberFormat().formatRange
>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, --, --))
>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)
>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, --, --))

new Intl.NumberFormat().formatRangeToParts
>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, --, --))
>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)
>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, --, --))

new Intl.DateTimeFormat().formatRange
>new Intl.DateTimeFormat().formatRange : Symbol(Intl.DateTimeFormat.formatRange, Decl(lib.es2021.intl.d.ts, --, --))
>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, --, --))
>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)
>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, --, --))
>formatRange : Symbol(Intl.DateTimeFormat.formatRange, Decl(lib.es2021.intl.d.ts, --, --))

new Intl.DateTimeFormat().formatRangeToParts
>new Intl.DateTimeFormat().formatRangeToParts : Symbol(Intl.DateTimeFormat.formatRangeToParts, Decl(lib.es2021.intl.d.ts, --, --))
>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, --, --))
>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)
>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, --, --))
>formatRangeToParts : Symbol(Intl.DateTimeFormat.formatRangeToParts, Decl(lib.es2021.intl.d.ts, --, --))

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
=== tests/cases/compiler/DateTimeFormatAndNumberFormatES2021.ts ===
Intl.NumberFormat.prototype.formatRange
>Intl.NumberFormat.prototype.formatRange : any
>Intl.NumberFormat.prototype : Intl.NumberFormat
>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; }
>Intl : typeof 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; }
>prototype : Intl.NumberFormat
>formatRange : any

Intl.DateTimeFormat.prototype.formatRange
>Intl.DateTimeFormat.prototype.formatRange : (startDate: number | bigint | Date, endDate: number | bigint | Date) => string
>Intl.DateTimeFormat.prototype : Intl.DateTimeFormat
>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; }
>Intl : typeof 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; }
>prototype : Intl.DateTimeFormat
>formatRange : (startDate: number | bigint | Date, endDate: number | bigint | Date) => string

new Intl.NumberFormat().formatRange
>new Intl.NumberFormat().formatRange : any
>new Intl.NumberFormat() : Intl.NumberFormat
>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; }
>Intl : typeof 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; }
>formatRange : any

new Intl.NumberFormat().formatRangeToParts
>new Intl.NumberFormat().formatRangeToParts : any
>new Intl.NumberFormat() : Intl.NumberFormat
>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; }
>Intl : typeof 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; }
>formatRangeToParts : any

new Intl.DateTimeFormat().formatRange
>new Intl.DateTimeFormat().formatRange : (startDate: number | bigint | Date, endDate: number | bigint | Date) => string
>new Intl.DateTimeFormat() : Intl.DateTimeFormat
>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; }
>Intl : typeof 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; }
>formatRange : (startDate: number | bigint | Date, endDate: number | bigint | Date) => string

new Intl.DateTimeFormat().formatRangeToParts
>new Intl.DateTimeFormat().formatRangeToParts : (startDate: number | bigint | Date, endDate: number | bigint | Date) => Intl.DateTimeFormatPart[]
>new Intl.DateTimeFormat() : Intl.DateTimeFormat
>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; }
>Intl : typeof 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; }
>formatRangeToParts : (startDate: number | bigint | Date, endDate: number | bigint | Date) => Intl.DateTimeFormatPart[]

8 changes: 4 additions & 4 deletions tests/baselines/reference/bigintWithLib.types
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,9 @@ new Intl.NumberFormat("fr").format(3000n);
>new Intl.NumberFormat("fr").format(3000n) : string
>new Intl.NumberFormat("fr").format : { (value: number): string; (value: number | bigint): string; }
>new Intl.NumberFormat("fr") : Intl.NumberFormat
>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[]; }
>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; }
>Intl : typeof 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[]; }
>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; }
>"fr" : "fr"
>format : { (value: number): string; (value: number | bigint): string; }
>3000n : 3000n
Expand All @@ -401,9 +401,9 @@ new Intl.NumberFormat("fr").format(bigintVal);
>new Intl.NumberFormat("fr").format(bigintVal) : string
>new Intl.NumberFormat("fr").format : { (value: number): string; (value: number | bigint): string; }
>new Intl.NumberFormat("fr") : Intl.NumberFormat
>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[]; }
>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; }
>Intl : typeof 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[]; }
>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; }
>"fr" : "fr"
>format : { (value: number): string; (value: number | bigint): string; }
>bigintVal : bigint
Expand Down
Loading