Skip to content

Commit 32a1370

Browse files
authored
Add missing parameters from Array.toLocaleString on ES2015 libs (#57679)
1 parent a39c43c commit 32a1370

35 files changed

+3369
-217
lines changed

src/lib/es2015.core.d.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ interface Array<T> {
4242
* @param end If not specified, length of the this object is used as its default value.
4343
*/
4444
copyWithin(target: number, start: number, end?: number): this;
45+
46+
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string;
4547
}
4648

4749
interface ArrayConstructor {
@@ -342,6 +344,8 @@ interface ReadonlyArray<T> {
342344
* predicate. If it is not provided, undefined is used instead.
343345
*/
344346
findIndex(predicate: (value: T, index: number, obj: readonly T[]) => unknown, thisArg?: any): number;
347+
348+
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string;
345349
}
346350

347351
interface RegExp {
@@ -537,3 +541,39 @@ interface StringConstructor {
537541
*/
538542
raw(template: { raw: readonly string[] | ArrayLike<string>; }, ...substitutions: any[]): string;
539543
}
544+
545+
interface Int8Array {
546+
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
547+
}
548+
549+
interface Uint8Array {
550+
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
551+
}
552+
553+
interface Uint8ClampedArray {
554+
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
555+
}
556+
557+
interface Int16Array {
558+
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
559+
}
560+
561+
interface Uint16Array {
562+
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
563+
}
564+
565+
interface Int32Array {
566+
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
567+
}
568+
569+
interface Uint32Array {
570+
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
571+
}
572+
573+
interface Float32Array {
574+
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
575+
}
576+
577+
interface Float64Array {
578+
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
579+
}

src/lib/es2020.bigint.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ interface BigInt64Array {
351351
subarray(begin?: number, end?: number): BigInt64Array;
352352

353353
/** Converts the array to a string by using the current locale. */
354-
toLocaleString(): string;
354+
toLocaleString(locales?: string | string[], options?: Intl.NumberFormatOptions): string;
355355

356356
/** Returns a string representation of the array. */
357357
toString(): string;
@@ -623,7 +623,7 @@ interface BigUint64Array {
623623
subarray(begin?: number, end?: number): BigUint64Array;
624624

625625
/** Converts the array to a string by using the current locale. */
626-
toLocaleString(): string;
626+
toLocaleString(locales?: string | string[], options?: Intl.NumberFormatOptions): string;
627627

628628
/** Returns a string representation of the array. */
629629
toString(): string;
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
//// [tests/cases/compiler/arrayToLocaleStringES2015.ts] ////
2+
3+
//// [arrayToLocaleStringES2015.ts]
4+
let str: string;
5+
const arr = [1, 2, 3];
6+
str = arr.toLocaleString(); // OK
7+
str = arr.toLocaleString('en-US'); // OK
8+
str = arr.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
9+
10+
const dates: readonly Date[] = [new Date(), new Date()];
11+
str = dates.toLocaleString(); // OK
12+
str = dates.toLocaleString('fr'); // OK
13+
str = dates.toLocaleString('fr', { timeZone: 'UTC' }); // OK
14+
15+
const mixed = [1, new Date(), 59782, new Date()];
16+
str = mixed.toLocaleString(); // OK
17+
str = mixed.toLocaleString('fr'); // OK
18+
str = mixed.toLocaleString('de', { style: 'currency', currency: 'EUR' }); // OK
19+
str = (mixed as ReadonlyArray<number | Date>).toLocaleString('de', { currency: 'EUR', style: 'currency', timeZone: 'UTC' }); // OK
20+
21+
const int8Array = new Int8Array(3);
22+
str = int8Array.toLocaleString(); // OK
23+
str = int8Array.toLocaleString('en-US'); // OK
24+
str = int8Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
25+
26+
const uint8Array = new Uint8Array(3);
27+
str = uint8Array.toLocaleString(); // OK
28+
str = uint8Array.toLocaleString('en-US'); // OK
29+
str = uint8Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
30+
31+
const uint8ClampedArray = new Uint8ClampedArray(3);
32+
str = uint8ClampedArray.toLocaleString(); // OK
33+
str = uint8ClampedArray.toLocaleString('en-US'); // OK
34+
str = uint8ClampedArray.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
35+
36+
const int16Array = new Int16Array(3);
37+
str = int16Array.toLocaleString(); // OK
38+
str = int16Array.toLocaleString('en-US'); // OK
39+
str = int16Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
40+
41+
const uint16Array = new Uint16Array(3);
42+
str = uint16Array.toLocaleString(); // OK
43+
str = uint16Array.toLocaleString('en-US'); // OK
44+
str = uint16Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
45+
46+
const int32Array = new Int32Array(3);
47+
str = int32Array.toLocaleString(); // OK
48+
str = int32Array.toLocaleString('en-US'); // OK
49+
str = int32Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
50+
51+
const uint32Array = new Uint32Array(3);
52+
str = uint32Array.toLocaleString(); // OK
53+
str = uint32Array.toLocaleString('en-US'); // OK
54+
str = uint32Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
55+
56+
const float32Array = new Float32Array(3);
57+
str = float32Array.toLocaleString(); // OK
58+
str = float32Array.toLocaleString('en-US'); // OK
59+
str = float32Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
60+
61+
const float64Array = new Float64Array(3);
62+
str = float64Array.toLocaleString(); // OK
63+
str = float64Array.toLocaleString('en-US'); // OK
64+
str = float64Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
65+
66+
67+
//// [arrayToLocaleStringES2015.js]
68+
let str;
69+
const arr = [1, 2, 3];
70+
str = arr.toLocaleString(); // OK
71+
str = arr.toLocaleString('en-US'); // OK
72+
str = arr.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
73+
const dates = [new Date(), new Date()];
74+
str = dates.toLocaleString(); // OK
75+
str = dates.toLocaleString('fr'); // OK
76+
str = dates.toLocaleString('fr', { timeZone: 'UTC' }); // OK
77+
const mixed = [1, new Date(), 59782, new Date()];
78+
str = mixed.toLocaleString(); // OK
79+
str = mixed.toLocaleString('fr'); // OK
80+
str = mixed.toLocaleString('de', { style: 'currency', currency: 'EUR' }); // OK
81+
str = mixed.toLocaleString('de', { currency: 'EUR', style: 'currency', timeZone: 'UTC' }); // OK
82+
const int8Array = new Int8Array(3);
83+
str = int8Array.toLocaleString(); // OK
84+
str = int8Array.toLocaleString('en-US'); // OK
85+
str = int8Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
86+
const uint8Array = new Uint8Array(3);
87+
str = uint8Array.toLocaleString(); // OK
88+
str = uint8Array.toLocaleString('en-US'); // OK
89+
str = uint8Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
90+
const uint8ClampedArray = new Uint8ClampedArray(3);
91+
str = uint8ClampedArray.toLocaleString(); // OK
92+
str = uint8ClampedArray.toLocaleString('en-US'); // OK
93+
str = uint8ClampedArray.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
94+
const int16Array = new Int16Array(3);
95+
str = int16Array.toLocaleString(); // OK
96+
str = int16Array.toLocaleString('en-US'); // OK
97+
str = int16Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
98+
const uint16Array = new Uint16Array(3);
99+
str = uint16Array.toLocaleString(); // OK
100+
str = uint16Array.toLocaleString('en-US'); // OK
101+
str = uint16Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
102+
const int32Array = new Int32Array(3);
103+
str = int32Array.toLocaleString(); // OK
104+
str = int32Array.toLocaleString('en-US'); // OK
105+
str = int32Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
106+
const uint32Array = new Uint32Array(3);
107+
str = uint32Array.toLocaleString(); // OK
108+
str = uint32Array.toLocaleString('en-US'); // OK
109+
str = uint32Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
110+
const float32Array = new Float32Array(3);
111+
str = float32Array.toLocaleString(); // OK
112+
str = float32Array.toLocaleString('en-US'); // OK
113+
str = float32Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
114+
const float64Array = new Float64Array(3);
115+
str = float64Array.toLocaleString(); // OK
116+
str = float64Array.toLocaleString('en-US'); // OK
117+
str = float64Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK

0 commit comments

Comments
 (0)