Skip to content

Commit d76e85d

Browse files
ShuiRuTianSong Gao
and
Song Gao
authored
Update bigint declaration file (#38526)
* update toLocalString function signature * update test. * fix lint * follow review advice. * format and better comment. * format * add case * fix symbol. * remove subtype and string union in interface. * remove useless code. Co-authored-by: Song Gao <song.gao@laserfiche.com>
1 parent d10beaa commit d76e85d

11 files changed

+479
-122
lines changed

src/lib/es2020.bigint.d.ts

+94-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,89 @@
1+
interface BigIntToLocaleStringOptions {
2+
/**
3+
* The locale matching algorithm to use.The default is "best fit". For information about this option, see the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation Intl page}.
4+
*/
5+
localeMatcher?: string;
6+
/**
7+
* The formatting style to use , the default is "decimal".
8+
*/
9+
style?: string;
10+
11+
numberingSystem?: string;
12+
/**
13+
* The unit to use in unit formatting, Possible values are core unit identifiers, defined in UTS #35, Part 2, Section 6. A subset of units from the full list was selected for use in ECMAScript. Pairs of simple units can be concatenated with "-per-" to make a compound unit. There is no default value; if the style is "unit", the unit property must be provided.
14+
*/
15+
unit?: string;
16+
17+
/**
18+
* The unit formatting style to use in unit formatting, the defaults is "short".
19+
*/
20+
unitDisplay?: string;
21+
22+
/**
23+
* The currency to use in currency formatting. Possible values are the ISO 4217 currency codes, such as "USD" for the US dollar, "EUR" for the euro, or "CNY" for the Chinese RMB — see the Current currency & funds code list. There is no default value; if the style is "currency", the currency property must be provided. It is only used when [[Style]] has the value "currency".
24+
*/
25+
currency?: string;
26+
27+
/**
28+
* How to display the currency in currency formatting. It is only used when [[Style]] has the value "currency". The default is "symbol".
29+
*
30+
* "symbol" to use a localized currency symbol such as €,
31+
*
32+
* "code" to use the ISO currency code,
33+
*
34+
* "name" to use a localized currency name such as "dollar"
35+
*/
36+
currencyDisplay?: string;
37+
38+
/**
39+
* Whether to use grouping separators, such as thousands separators or thousand/lakh/crore separators. The default is true.
40+
*/
41+
useGrouping?: boolean;
42+
43+
/**
44+
* The minimum number of integer digits to use. Possible values are from 1 to 21; the default is 1.
45+
*/
46+
minimumIntegerDigits?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21;
47+
48+
/**
49+
* The minimum number of fraction digits to use. Possible values are from 0 to 20; the default for plain number and percent formatting is 0; the default for currency formatting is the number of minor unit digits provided by the {@link http://www.currency-iso.org/en/home/tables/table-a1.html ISO 4217 currency codes list} (2 if the list doesn't provide that information).
50+
*/
51+
minimumFractionDigits?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20;
52+
53+
/**
54+
* The maximum number of fraction digits to use. Possible values are from 0 to 20; the default for plain number formatting is the larger of minimumFractionDigits and 3; the default for currency formatting is the larger of minimumFractionDigits and the number of minor unit digits provided by the {@link http://www.currency-iso.org/en/home/tables/table-a1.html ISO 4217 currency codes list} (2 if the list doesn't provide that information); the default for percent formatting is the larger of minimumFractionDigits and 0.
55+
*/
56+
maximumFractionDigits?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20;
57+
58+
/**
59+
* The minimum number of significant digits to use. Possible values are from 1 to 21; the default is 1.
60+
*/
61+
minimumSignificantDigits?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21;
62+
63+
/**
64+
* The maximum number of significant digits to use. Possible values are from 1 to 21; the default is 21.
65+
*/
66+
maximumSignificantDigits?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21;
67+
68+
/**
69+
* The formatting that should be displayed for the number, the defaults is "standard"
70+
*
71+
* "standard" plain number formatting
72+
*
73+
* "scientific" return the order-of-magnitude for formatted number.
74+
*
75+
* "engineering" return the exponent of ten when divisible by three
76+
*
77+
* "compact" string representing exponent, defaults is using the "short" form
78+
*/
79+
notation?: string;
80+
81+
/**
82+
* used only when notation is "compact"
83+
*/
84+
compactDisplay?: string;
85+
}
86+
187
interface BigInt {
288
/**
389
* Returns a string representation of an object.
@@ -6,7 +92,7 @@ interface BigInt {
692
toString(radix?: number): string;
793

894
/** Returns a string representation appropriate to the host environment's current locale. */
9-
toLocaleString(): string;
95+
toLocaleString(locales?: string, options?: BigIntToLocaleStringOptions): string;
1096

1197
/** Returns the primitive value of the specified object. */
1298
valueOf(): bigint;
@@ -613,3 +699,10 @@ interface DataView {
613699
*/
614700
setBigUint64(byteOffset: number, value: bigint, littleEndian?: boolean): void;
615701
}
702+
703+
declare namespace Intl{
704+
interface NumberFormat {
705+
format(value: number | bigint): string;
706+
resolvedOptions(): ResolvedNumberFormatOptions;
707+
}
708+
}

tests/baselines/reference/bigintWithLib.errors.txt

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/compiler/bigintWithLib.ts(4,1): error TS2350: Only a void function can be called with the 'new' keyword.
2-
tests/cases/compiler/bigintWithLib.ts(16,33): error TS2769: No overload matches this call.
2+
tests/cases/compiler/bigintWithLib.ts(19,33): error TS2769: No overload matches this call.
33
Overload 1 of 3, '(length?: number): BigInt64Array', gave the following error.
44
Argument of type 'number[]' is not assignable to parameter of type 'number'.
55
Overload 2 of 3, '(array: Iterable<bigint>): BigInt64Array', gave the following error.
@@ -12,18 +12,18 @@ tests/cases/compiler/bigintWithLib.ts(16,33): error TS2769: No overload matches
1212
Overload 3 of 3, '(buffer: ArrayBufferLike, byteOffset?: number, length?: number): BigInt64Array', gave the following error.
1313
Argument of type 'number[]' is not assignable to parameter of type 'ArrayBufferLike'.
1414
Type 'number[]' is missing the following properties from type 'SharedArrayBuffer': byteLength, [Symbol.species], [Symbol.toStringTag]
15-
tests/cases/compiler/bigintWithLib.ts(21,13): error TS2540: Cannot assign to 'length' because it is a read-only property.
16-
tests/cases/compiler/bigintWithLib.ts(28,35): error TS2769: No overload matches this call.
15+
tests/cases/compiler/bigintWithLib.ts(24,13): error TS2540: Cannot assign to 'length' because it is a read-only property.
16+
tests/cases/compiler/bigintWithLib.ts(31,35): error TS2769: No overload matches this call.
1717
Overload 1 of 3, '(length?: number): BigUint64Array', gave the following error.
1818
Argument of type 'number[]' is not assignable to parameter of type 'number'.
1919
Overload 2 of 3, '(array: Iterable<bigint>): BigUint64Array', gave the following error.
2020
Argument of type 'number[]' is not assignable to parameter of type 'Iterable<bigint>'.
2121
Overload 3 of 3, '(buffer: ArrayBufferLike, byteOffset?: number, length?: number): BigUint64Array', gave the following error.
2222
Argument of type 'number[]' is not assignable to parameter of type 'ArrayBufferLike'.
2323
Type 'number[]' is not assignable to type 'SharedArrayBuffer'.
24-
tests/cases/compiler/bigintWithLib.ts(33,13): error TS2540: Cannot assign to 'length' because it is a read-only property.
25-
tests/cases/compiler/bigintWithLib.ts(40,25): error TS2345: Argument of type 'number' is not assignable to parameter of type 'bigint'.
26-
tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type 'number' is not assignable to parameter of type 'bigint'.
24+
tests/cases/compiler/bigintWithLib.ts(36,13): error TS2540: Cannot assign to 'length' because it is a read-only property.
25+
tests/cases/compiler/bigintWithLib.ts(43,25): error TS2345: Argument of type 'number' is not assignable to parameter of type 'bigint'.
26+
tests/cases/compiler/bigintWithLib.ts(46,26): error TS2345: Argument of type 'number' is not assignable to parameter of type 'bigint'.
2727

2828

2929
==== tests/cases/compiler/bigintWithLib.ts (7 errors) ====
@@ -39,6 +39,9 @@ tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type 'nu
3939
let stringVal: string = bigintVal.toString();
4040
stringVal = bigintVal.toString(2);
4141
stringVal = bigintVal.toLocaleString();
42+
stringVal = bigintVal.toLocaleString('de-DE');
43+
stringVal = bigintVal.toLocaleString('de-DE', { style: 'currency' });
44+
stringVal = bigintVal.toLocaleString('de-DE', { style: 'currency', currency: 'EUR' })
4245

4346
// Test BigInt64Array
4447
let bigIntArray: BigInt64Array = new BigInt64Array();
@@ -113,4 +116,8 @@ tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type 'nu
113116
const x = -12n; // should emit as const x = -12n
114117
const y: 12n = 12n; // should emit type 12n
115118
let z = 12n; // should emit type bigint in declaration file
119+
120+
// Test Intl methods with new parameter type
121+
new Intl.NumberFormat("fr").format(3000n);
122+
new Intl.NumberFormat("fr").format(bigintVal);
116123

tests/baselines/reference/bigintWithLib.js

+13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ bigintVal = bigintVal.valueOf();
99
let stringVal: string = bigintVal.toString();
1010
stringVal = bigintVal.toString(2);
1111
stringVal = bigintVal.toLocaleString();
12+
stringVal = bigintVal.toLocaleString('de-DE');
13+
stringVal = bigintVal.toLocaleString('de-DE', { style: 'currency' });
14+
stringVal = bigintVal.toLocaleString('de-DE', { style: 'currency', currency: 'EUR' })
1215

1316
// Test BigInt64Array
1417
let bigIntArray: BigInt64Array = new BigInt64Array();
@@ -52,6 +55,10 @@ const w = 12n; // should emit as const w = 12n
5255
const x = -12n; // should emit as const x = -12n
5356
const y: 12n = 12n; // should emit type 12n
5457
let z = 12n; // should emit type bigint in declaration file
58+
59+
// Test Intl methods with new parameter type
60+
new Intl.NumberFormat("fr").format(3000n);
61+
new Intl.NumberFormat("fr").format(bigintVal);
5562

5663

5764
//// [bigintWithLib.js]
@@ -65,6 +72,9 @@ bigintVal = bigintVal.valueOf();
6572
let stringVal = bigintVal.toString();
6673
stringVal = bigintVal.toString(2);
6774
stringVal = bigintVal.toLocaleString();
75+
stringVal = bigintVal.toLocaleString('de-DE');
76+
stringVal = bigintVal.toLocaleString('de-DE', { style: 'currency' });
77+
stringVal = bigintVal.toLocaleString('de-DE', { style: 'currency', currency: 'EUR' });
6878
// Test BigInt64Array
6979
let bigIntArray = new BigInt64Array();
7080
bigIntArray = new BigInt64Array(10);
@@ -104,6 +114,9 @@ const w = 12n; // should emit as const w = 12n
104114
const x = -12n; // should emit as const x = -12n
105115
const y = 12n; // should emit type 12n
106116
let z = 12n; // should emit type bigint in declaration file
117+
// Test Intl methods with new parameter type
118+
new Intl.NumberFormat("fr").format(3000n);
119+
new Intl.NumberFormat("fr").format(bigintVal);
107120

108121

109122
//// [bigintWithLib.d.ts]

0 commit comments

Comments
 (0)