Skip to content

Commit e5758ab

Browse files
authored
Make typed arrays generic over ArrayBufferLike (#59417)
1 parent fa0080f commit e5758ab

File tree

63 files changed

+33445
-4221
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+33445
-4221
lines changed

src/lib/es2015.core.d.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -542,38 +542,38 @@ interface StringConstructor {
542542
raw(template: { raw: readonly string[] | ArrayLike<string>; }, ...substitutions: any[]): string;
543543
}
544544

545-
interface Int8Array {
545+
interface Int8Array<TArrayBuffer extends ArrayBufferLike> {
546546
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
547547
}
548548

549-
interface Uint8Array {
549+
interface Uint8Array<TArrayBuffer extends ArrayBufferLike> {
550550
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
551551
}
552552

553-
interface Uint8ClampedArray {
553+
interface Uint8ClampedArray<TArrayBuffer extends ArrayBufferLike> {
554554
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
555555
}
556556

557-
interface Int16Array {
557+
interface Int16Array<TArrayBuffer extends ArrayBufferLike> {
558558
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
559559
}
560560

561-
interface Uint16Array {
561+
interface Uint16Array<TArrayBuffer extends ArrayBufferLike> {
562562
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
563563
}
564564

565-
interface Int32Array {
565+
interface Int32Array<TArrayBuffer extends ArrayBufferLike> {
566566
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
567567
}
568568

569-
interface Uint32Array {
569+
interface Uint32Array<TArrayBuffer extends ArrayBufferLike> {
570570
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
571571
}
572572

573-
interface Float32Array {
573+
interface Float32Array<TArrayBuffer extends ArrayBufferLike> {
574574
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
575575
}
576576

577-
interface Float64Array {
577+
interface Float64Array<TArrayBuffer extends ArrayBufferLike> {
578578
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
579579
}

src/lib/es2015.iterable.d.ts

Lines changed: 90 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ interface String {
252252
[Symbol.iterator](): StringIterator<string>;
253253
}
254254

255-
interface Int8Array {
255+
interface Int8Array<TArrayBuffer extends ArrayBufferLike> {
256256
[Symbol.iterator](): ArrayIterator<number>;
257257
/**
258258
* Returns an array of key, value pairs for every entry in the array
@@ -269,18 +269,25 @@ interface Int8Array {
269269
}
270270

271271
interface Int8ArrayConstructor {
272-
new (elements: Iterable<number>): Int8Array;
272+
new (elements: Iterable<number>): Int8Array<ArrayBuffer>;
273273

274274
/**
275275
* Creates an array from an array-like or iterable object.
276276
* @param arrayLike An array-like or iterable object to convert to an array.
277277
* @param mapfn A mapping function to call on every element of the array.
278278
* @param thisArg Value of 'this' used to invoke the mapfn.
279279
*/
280-
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int8Array;
280+
from(arrayLike: Iterable<number>): Int8Array<ArrayBuffer>;
281+
/**
282+
* Creates an array from an array-like or iterable object.
283+
* @param arrayLike An array-like or iterable object to convert to an array.
284+
* @param mapfn A mapping function to call on every element of the array.
285+
* @param thisArg Value of 'this' used to invoke the mapfn.
286+
*/
287+
from<T>(arrayLike: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Int8Array<ArrayBuffer>;
281288
}
282289

283-
interface Uint8Array {
290+
interface Uint8Array<TArrayBuffer extends ArrayBufferLike> {
284291
[Symbol.iterator](): ArrayIterator<number>;
285292
/**
286293
* Returns an array of key, value pairs for every entry in the array
@@ -297,18 +304,25 @@ interface Uint8Array {
297304
}
298305

299306
interface Uint8ArrayConstructor {
300-
new (elements: Iterable<number>): Uint8Array;
307+
new (elements: Iterable<number>): Uint8Array<ArrayBuffer>;
301308

302309
/**
303310
* Creates an array from an array-like or iterable object.
304311
* @param arrayLike An array-like or iterable object to convert to an array.
305312
* @param mapfn A mapping function to call on every element of the array.
306313
* @param thisArg Value of 'this' used to invoke the mapfn.
307314
*/
308-
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8Array;
315+
from(arrayLike: Iterable<number>): Uint8Array<ArrayBuffer>;
316+
/**
317+
* Creates an array from an array-like or iterable object.
318+
* @param arrayLike An array-like or iterable object to convert to an array.
319+
* @param mapfn A mapping function to call on every element of the array.
320+
* @param thisArg Value of 'this' used to invoke the mapfn.
321+
*/
322+
from<T>(arrayLike: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Uint8Array<ArrayBuffer>;
309323
}
310324

311-
interface Uint8ClampedArray {
325+
interface Uint8ClampedArray<TArrayBuffer extends ArrayBufferLike> {
312326
[Symbol.iterator](): ArrayIterator<number>;
313327
/**
314328
* Returns an array of key, value pairs for every entry in the array
@@ -327,18 +341,25 @@ interface Uint8ClampedArray {
327341
}
328342

329343
interface Uint8ClampedArrayConstructor {
330-
new (elements: Iterable<number>): Uint8ClampedArray;
344+
new (elements: Iterable<number>): Uint8ClampedArray<ArrayBuffer>;
331345

332346
/**
333347
* Creates an array from an array-like or iterable object.
334348
* @param arrayLike An array-like or iterable object to convert to an array.
335349
* @param mapfn A mapping function to call on every element of the array.
336350
* @param thisArg Value of 'this' used to invoke the mapfn.
337351
*/
338-
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8ClampedArray;
352+
from(arrayLike: Iterable<number>): Uint8ClampedArray<ArrayBuffer>;
353+
/**
354+
* Creates an array from an array-like or iterable object.
355+
* @param arrayLike An array-like or iterable object to convert to an array.
356+
* @param mapfn A mapping function to call on every element of the array.
357+
* @param thisArg Value of 'this' used to invoke the mapfn.
358+
*/
359+
from<T>(arrayLike: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Uint8ClampedArray<ArrayBuffer>;
339360
}
340361

341-
interface Int16Array {
362+
interface Int16Array<TArrayBuffer extends ArrayBufferLike> {
342363
[Symbol.iterator](): ArrayIterator<number>;
343364
/**
344365
* Returns an array of key, value pairs for every entry in the array
@@ -357,18 +378,25 @@ interface Int16Array {
357378
}
358379

359380
interface Int16ArrayConstructor {
360-
new (elements: Iterable<number>): Int16Array;
381+
new (elements: Iterable<number>): Int16Array<ArrayBuffer>;
361382

362383
/**
363384
* Creates an array from an array-like or iterable object.
364385
* @param arrayLike An array-like or iterable object to convert to an array.
365386
* @param mapfn A mapping function to call on every element of the array.
366387
* @param thisArg Value of 'this' used to invoke the mapfn.
367388
*/
368-
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int16Array;
389+
from(arrayLike: Iterable<number>): Int16Array<ArrayBuffer>;
390+
/**
391+
* Creates an array from an array-like or iterable object.
392+
* @param arrayLike An array-like or iterable object to convert to an array.
393+
* @param mapfn A mapping function to call on every element of the array.
394+
* @param thisArg Value of 'this' used to invoke the mapfn.
395+
*/
396+
from<T>(arrayLike: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Int16Array<ArrayBuffer>;
369397
}
370398

371-
interface Uint16Array {
399+
interface Uint16Array<TArrayBuffer extends ArrayBufferLike> {
372400
[Symbol.iterator](): ArrayIterator<number>;
373401
/**
374402
* Returns an array of key, value pairs for every entry in the array
@@ -385,18 +413,25 @@ interface Uint16Array {
385413
}
386414

387415
interface Uint16ArrayConstructor {
388-
new (elements: Iterable<number>): Uint16Array;
416+
new (elements: Iterable<number>): Uint16Array<ArrayBuffer>;
389417

390418
/**
391419
* Creates an array from an array-like or iterable object.
392420
* @param arrayLike An array-like or iterable object to convert to an array.
393421
* @param mapfn A mapping function to call on every element of the array.
394422
* @param thisArg Value of 'this' used to invoke the mapfn.
395423
*/
396-
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint16Array;
424+
from(arrayLike: Iterable<number>): Uint16Array<ArrayBuffer>;
425+
/**
426+
* Creates an array from an array-like or iterable object.
427+
* @param arrayLike An array-like or iterable object to convert to an array.
428+
* @param mapfn A mapping function to call on every element of the array.
429+
* @param thisArg Value of 'this' used to invoke the mapfn.
430+
*/
431+
from<T>(arrayLike: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Uint16Array<ArrayBuffer>;
397432
}
398433

399-
interface Int32Array {
434+
interface Int32Array<TArrayBuffer extends ArrayBufferLike> {
400435
[Symbol.iterator](): ArrayIterator<number>;
401436
/**
402437
* Returns an array of key, value pairs for every entry in the array
@@ -413,18 +448,25 @@ interface Int32Array {
413448
}
414449

415450
interface Int32ArrayConstructor {
416-
new (elements: Iterable<number>): Int32Array;
451+
new (elements: Iterable<number>): Int32Array<ArrayBuffer>;
417452

418453
/**
419454
* Creates an array from an array-like or iterable object.
420455
* @param arrayLike An array-like or iterable object to convert to an array.
421456
* @param mapfn A mapping function to call on every element of the array.
422457
* @param thisArg Value of 'this' used to invoke the mapfn.
423458
*/
424-
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int32Array;
459+
from(arrayLike: Iterable<number>): Int32Array<ArrayBuffer>;
460+
/**
461+
* Creates an array from an array-like or iterable object.
462+
* @param arrayLike An array-like or iterable object to convert to an array.
463+
* @param mapfn A mapping function to call on every element of the array.
464+
* @param thisArg Value of 'this' used to invoke the mapfn.
465+
*/
466+
from<T>(arrayLike: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Int32Array<ArrayBuffer>;
425467
}
426468

427-
interface Uint32Array {
469+
interface Uint32Array<TArrayBuffer extends ArrayBufferLike> {
428470
[Symbol.iterator](): ArrayIterator<number>;
429471
/**
430472
* Returns an array of key, value pairs for every entry in the array
@@ -441,18 +483,25 @@ interface Uint32Array {
441483
}
442484

443485
interface Uint32ArrayConstructor {
444-
new (elements: Iterable<number>): Uint32Array;
486+
new (elements: Iterable<number>): Uint32Array<ArrayBuffer>;
445487

446488
/**
447489
* Creates an array from an array-like or iterable object.
448490
* @param arrayLike An array-like or iterable object to convert to an array.
449491
* @param mapfn A mapping function to call on every element of the array.
450492
* @param thisArg Value of 'this' used to invoke the mapfn.
451493
*/
452-
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint32Array;
494+
from(arrayLike: Iterable<number>): Uint32Array<ArrayBuffer>;
495+
/**
496+
* Creates an array from an array-like or iterable object.
497+
* @param arrayLike An array-like or iterable object to convert to an array.
498+
* @param mapfn A mapping function to call on every element of the array.
499+
* @param thisArg Value of 'this' used to invoke the mapfn.
500+
*/
501+
from<T>(arrayLike: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Uint32Array<ArrayBuffer>;
453502
}
454503

455-
interface Float32Array {
504+
interface Float32Array<TArrayBuffer extends ArrayBufferLike> {
456505
[Symbol.iterator](): ArrayIterator<number>;
457506
/**
458507
* Returns an array of key, value pairs for every entry in the array
@@ -469,18 +518,25 @@ interface Float32Array {
469518
}
470519

471520
interface Float32ArrayConstructor {
472-
new (elements: Iterable<number>): Float32Array;
521+
new (elements: Iterable<number>): Float32Array<ArrayBuffer>;
473522

474523
/**
475524
* Creates an array from an array-like or iterable object.
476525
* @param arrayLike An array-like or iterable object to convert to an array.
477526
* @param mapfn A mapping function to call on every element of the array.
478527
* @param thisArg Value of 'this' used to invoke the mapfn.
479528
*/
480-
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Float32Array;
529+
from(arrayLike: Iterable<number>): Float32Array<ArrayBuffer>;
530+
/**
531+
* Creates an array from an array-like or iterable object.
532+
* @param arrayLike An array-like or iterable object to convert to an array.
533+
* @param mapfn A mapping function to call on every element of the array.
534+
* @param thisArg Value of 'this' used to invoke the mapfn.
535+
*/
536+
from<T>(arrayLike: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Float32Array<ArrayBuffer>;
481537
}
482538

483-
interface Float64Array {
539+
interface Float64Array<TArrayBuffer extends ArrayBufferLike> {
484540
[Symbol.iterator](): ArrayIterator<number>;
485541
/**
486542
* Returns an array of key, value pairs for every entry in the array
@@ -497,13 +553,20 @@ interface Float64Array {
497553
}
498554

499555
interface Float64ArrayConstructor {
500-
new (elements: Iterable<number>): Float64Array;
556+
new (elements: Iterable<number>): Float64Array<ArrayBuffer>;
501557

502558
/**
503559
* Creates an array from an array-like or iterable object.
504560
* @param arrayLike An array-like or iterable object to convert to an array.
505561
* @param mapfn A mapping function to call on every element of the array.
506562
* @param thisArg Value of 'this' used to invoke the mapfn.
507563
*/
508-
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Float64Array;
564+
from(arrayLike: Iterable<number>): Float64Array<ArrayBuffer>;
565+
/**
566+
* Creates an array from an array-like or iterable object.
567+
* @param arrayLike An array-like or iterable object to convert to an array.
568+
* @param mapfn A mapping function to call on every element of the array.
569+
* @param thisArg Value of 'this' used to invoke the mapfn.
570+
*/
571+
from<T>(arrayLike: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Float64Array<ArrayBuffer>;
509572
}

src/lib/es2015.symbol.wellknown.d.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,43 +254,43 @@ interface ArrayBuffer {
254254
readonly [Symbol.toStringTag]: string;
255255
}
256256

257-
interface DataView {
257+
interface DataView<TArrayBuffer extends ArrayBufferLike> {
258258
readonly [Symbol.toStringTag]: string;
259259
}
260260

261-
interface Int8Array {
261+
interface Int8Array<TArrayBuffer extends ArrayBufferLike> {
262262
readonly [Symbol.toStringTag]: "Int8Array";
263263
}
264264

265-
interface Uint8Array {
265+
interface Uint8Array<TArrayBuffer extends ArrayBufferLike> {
266266
readonly [Symbol.toStringTag]: "Uint8Array";
267267
}
268268

269-
interface Uint8ClampedArray {
269+
interface Uint8ClampedArray<TArrayBuffer extends ArrayBufferLike> {
270270
readonly [Symbol.toStringTag]: "Uint8ClampedArray";
271271
}
272272

273-
interface Int16Array {
273+
interface Int16Array<TArrayBuffer extends ArrayBufferLike> {
274274
readonly [Symbol.toStringTag]: "Int16Array";
275275
}
276276

277-
interface Uint16Array {
277+
interface Uint16Array<TArrayBuffer extends ArrayBufferLike> {
278278
readonly [Symbol.toStringTag]: "Uint16Array";
279279
}
280280

281-
interface Int32Array {
281+
interface Int32Array<TArrayBuffer extends ArrayBufferLike> {
282282
readonly [Symbol.toStringTag]: "Int32Array";
283283
}
284284

285-
interface Uint32Array {
285+
interface Uint32Array<TArrayBuffer extends ArrayBufferLike> {
286286
readonly [Symbol.toStringTag]: "Uint32Array";
287287
}
288288

289-
interface Float32Array {
289+
interface Float32Array<TArrayBuffer extends ArrayBufferLike> {
290290
readonly [Symbol.toStringTag]: "Float32Array";
291291
}
292292

293-
interface Float64Array {
293+
interface Float64Array<TArrayBuffer extends ArrayBufferLike> {
294294
readonly [Symbol.toStringTag]: "Float64Array";
295295
}
296296

0 commit comments

Comments
 (0)