Skip to content
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

Add missing parameters from Array.toLocaleString on ES2015 libs #57679

Merged
merged 15 commits into from
Mar 27, 2024
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
40 changes: 40 additions & 0 deletions src/lib/es2015.core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ interface Array<T> {
* @param end If not specified, length of the this object is used as its default value.
*/
copyWithin(target: number, start: number, end?: number): this;

toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string;
}

interface ArrayConstructor {
Expand Down Expand Up @@ -342,6 +344,8 @@ interface ReadonlyArray<T> {
* predicate. If it is not provided, undefined is used instead.
*/
findIndex(predicate: (value: T, index: number, obj: readonly T[]) => unknown, thisArg?: any): number;

toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string;
}

interface RegExp {
Expand Down Expand Up @@ -537,3 +541,39 @@ interface StringConstructor {
*/
raw(template: { raw: readonly string[] | ArrayLike<string>; }, ...substitutions: any[]): string;
}

interface Int8Array {
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
}

interface Uint8Array {
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
}

interface Uint8ClampedArray {
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
}

interface Int16Array {
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
}

interface Uint16Array {
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
}

interface Int32Array {
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
}

interface Uint32Array {
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
}

interface Float32Array {
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
}

interface Float64Array {
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
}
4 changes: 2 additions & 2 deletions src/lib/es2020.bigint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ interface BigInt64Array {
subarray(begin?: number, end?: number): BigInt64Array;

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

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

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

/** Returns a string representation of the array. */
toString(): string;
Expand Down
117 changes: 117 additions & 0 deletions tests/baselines/reference/arrayToLocaleStringES2015.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
//// [tests/cases/compiler/arrayToLocaleStringES2015.ts] ////

//// [arrayToLocaleStringES2015.ts]
let str: string;
const arr = [1, 2, 3];
str = arr.toLocaleString(); // OK
str = arr.toLocaleString('en-US'); // OK
str = arr.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK

const dates: readonly Date[] = [new Date(), new Date()];
str = dates.toLocaleString(); // OK
str = dates.toLocaleString('fr'); // OK
str = dates.toLocaleString('fr', { timeZone: 'UTC' }); // OK

const mixed = [1, new Date(), 59782, new Date()];
str = mixed.toLocaleString(); // OK
str = mixed.toLocaleString('fr'); // OK
str = mixed.toLocaleString('de', { style: 'currency', currency: 'EUR' }); // OK
str = (mixed as ReadonlyArray<number | Date>).toLocaleString('de', { currency: 'EUR', style: 'currency', timeZone: 'UTC' }); // OK

const int8Array = new Int8Array(3);
str = int8Array.toLocaleString(); // OK
str = int8Array.toLocaleString('en-US'); // OK
str = int8Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK

const uint8Array = new Uint8Array(3);
str = uint8Array.toLocaleString(); // OK
str = uint8Array.toLocaleString('en-US'); // OK
str = uint8Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK

const uint8ClampedArray = new Uint8ClampedArray(3);
str = uint8ClampedArray.toLocaleString(); // OK
str = uint8ClampedArray.toLocaleString('en-US'); // OK
str = uint8ClampedArray.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK

const int16Array = new Int16Array(3);
str = int16Array.toLocaleString(); // OK
str = int16Array.toLocaleString('en-US'); // OK
str = int16Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK

const uint16Array = new Uint16Array(3);
str = uint16Array.toLocaleString(); // OK
str = uint16Array.toLocaleString('en-US'); // OK
str = uint16Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK

const int32Array = new Int32Array(3);
str = int32Array.toLocaleString(); // OK
str = int32Array.toLocaleString('en-US'); // OK
str = int32Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK

const uint32Array = new Uint32Array(3);
str = uint32Array.toLocaleString(); // OK
str = uint32Array.toLocaleString('en-US'); // OK
str = uint32Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK

const float32Array = new Float32Array(3);
str = float32Array.toLocaleString(); // OK
str = float32Array.toLocaleString('en-US'); // OK
str = float32Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK

const float64Array = new Float64Array(3);
str = float64Array.toLocaleString(); // OK
str = float64Array.toLocaleString('en-US'); // OK
str = float64Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK


//// [arrayToLocaleStringES2015.js]
let str;
const arr = [1, 2, 3];
str = arr.toLocaleString(); // OK
str = arr.toLocaleString('en-US'); // OK
str = arr.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
const dates = [new Date(), new Date()];
str = dates.toLocaleString(); // OK
str = dates.toLocaleString('fr'); // OK
str = dates.toLocaleString('fr', { timeZone: 'UTC' }); // OK
const mixed = [1, new Date(), 59782, new Date()];
str = mixed.toLocaleString(); // OK
str = mixed.toLocaleString('fr'); // OK
str = mixed.toLocaleString('de', { style: 'currency', currency: 'EUR' }); // OK
str = mixed.toLocaleString('de', { currency: 'EUR', style: 'currency', timeZone: 'UTC' }); // OK
const int8Array = new Int8Array(3);
str = int8Array.toLocaleString(); // OK
str = int8Array.toLocaleString('en-US'); // OK
str = int8Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
const uint8Array = new Uint8Array(3);
str = uint8Array.toLocaleString(); // OK
str = uint8Array.toLocaleString('en-US'); // OK
str = uint8Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
const uint8ClampedArray = new Uint8ClampedArray(3);
str = uint8ClampedArray.toLocaleString(); // OK
str = uint8ClampedArray.toLocaleString('en-US'); // OK
str = uint8ClampedArray.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
const int16Array = new Int16Array(3);
str = int16Array.toLocaleString(); // OK
str = int16Array.toLocaleString('en-US'); // OK
str = int16Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
const uint16Array = new Uint16Array(3);
str = uint16Array.toLocaleString(); // OK
str = uint16Array.toLocaleString('en-US'); // OK
str = uint16Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
const int32Array = new Int32Array(3);
str = int32Array.toLocaleString(); // OK
str = int32Array.toLocaleString('en-US'); // OK
str = int32Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
const uint32Array = new Uint32Array(3);
str = uint32Array.toLocaleString(); // OK
str = uint32Array.toLocaleString('en-US'); // OK
str = uint32Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
const float32Array = new Float32Array(3);
str = float32Array.toLocaleString(); // OK
str = float32Array.toLocaleString('en-US'); // OK
str = float32Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
const float64Array = new Float64Array(3);
str = float64Array.toLocaleString(); // OK
str = float64Array.toLocaleString('en-US'); // OK
str = float64Array.toLocaleString('en-US', { style: 'currency', currency: 'EUR' }); // OK
Loading