Skip to content

Commit fde2c55

Browse files
authored
fix(43799): Support bigint type for Intl.NumberFormat.formatToParts (microsoft#44015)
* Add bigint support for formatToParts * Add tests for Intl.NumberFormat.formatToParts * Cleanup test * Fix EOL symbols * Update baseline test
1 parent 3f9e724 commit fde2c55

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

src/lib/esnext.intl.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ declare namespace Intl {
77
}
88

99
interface NumberFormat {
10-
formatToParts(number?: number): NumberFormatPart[];
10+
formatToParts(number?: number | bigint): NumberFormatPart[];
1111
}
1212
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [formatToPartsBigInt.ts]
2+
// Intl.NumberFormat.formatToParts should support bigInt
3+
4+
// Test Intl methods with new parameter type
5+
new Intl.NumberFormat("fr").formatToParts(3000n);
6+
new Intl.NumberFormat("fr").formatToParts(BigInt(123));
7+
8+
9+
//// [formatToPartsBigInt.js]
10+
// Intl.NumberFormat.formatToParts should support bigInt
11+
// Test Intl methods with new parameter type
12+
new Intl.NumberFormat("fr").formatToParts(3000n);
13+
new Intl.NumberFormat("fr").formatToParts(BigInt(123));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== tests/cases/compiler/formatToPartsBigInt.ts ===
2+
// Intl.NumberFormat.formatToParts should support bigInt
3+
4+
// Test Intl methods with new parameter type
5+
new Intl.NumberFormat("fr").formatToParts(3000n);
6+
>new Intl.NumberFormat("fr").formatToParts : Symbol(Intl.NumberFormat.formatToParts, Decl(lib.esnext.intl.d.ts, --, --))
7+
>Intl.NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.esnext.intl.d.ts, --, --))
8+
>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)
9+
>NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.esnext.intl.d.ts, --, --))
10+
>formatToParts : Symbol(Intl.NumberFormat.formatToParts, Decl(lib.esnext.intl.d.ts, --, --))
11+
12+
new Intl.NumberFormat("fr").formatToParts(BigInt(123));
13+
>new Intl.NumberFormat("fr").formatToParts : Symbol(Intl.NumberFormat.formatToParts, Decl(lib.esnext.intl.d.ts, --, --))
14+
>Intl.NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.esnext.intl.d.ts, --, --))
15+
>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)
16+
>NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.esnext.intl.d.ts, --, --))
17+
>formatToParts : Symbol(Intl.NumberFormat.formatToParts, Decl(lib.esnext.intl.d.ts, --, --))
18+
>BigInt : Symbol(BigInt, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
=== tests/cases/compiler/formatToPartsBigInt.ts ===
2+
// Intl.NumberFormat.formatToParts should support bigInt
3+
4+
// Test Intl methods with new parameter type
5+
new Intl.NumberFormat("fr").formatToParts(3000n);
6+
>new Intl.NumberFormat("fr").formatToParts(3000n) : Intl.NumberFormatPart[]
7+
>new Intl.NumberFormat("fr").formatToParts : (number?: number | bigint) => Intl.NumberFormatPart[]
8+
>new Intl.NumberFormat("fr") : Intl.NumberFormat
9+
>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[]; }
10+
>Intl : typeof Intl
11+
>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[]; }
12+
>"fr" : "fr"
13+
>formatToParts : (number?: number | bigint) => Intl.NumberFormatPart[]
14+
>3000n : 3000n
15+
16+
new Intl.NumberFormat("fr").formatToParts(BigInt(123));
17+
>new Intl.NumberFormat("fr").formatToParts(BigInt(123)) : Intl.NumberFormatPart[]
18+
>new Intl.NumberFormat("fr").formatToParts : (number?: number | bigint) => Intl.NumberFormatPart[]
19+
>new Intl.NumberFormat("fr") : Intl.NumberFormat
20+
>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[]; }
21+
>Intl : typeof Intl
22+
>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[]; }
23+
>"fr" : "fr"
24+
>formatToParts : (number?: number | bigint) => Intl.NumberFormatPart[]
25+
>BigInt(123) : bigint
26+
>BigInt : BigIntConstructor
27+
>123 : 123
28+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @target: esnext
2+
3+
// Intl.NumberFormat.formatToParts should support bigInt
4+
5+
// Test Intl methods with new parameter type
6+
new Intl.NumberFormat("fr").formatToParts(3000n);
7+
new Intl.NumberFormat("fr").formatToParts(BigInt(123));

0 commit comments

Comments
 (0)