Skip to content

Commit e6cc267

Browse files
thisArg types
1 parent c5b5be4 commit e6cc267

File tree

2 files changed

+80
-50
lines changed

2 files changed

+80
-50
lines changed

lib/lib.es2015.collection.d.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
interface Map<K, V> {
22
clear(): void;
33
delete(key: K): boolean;
4-
forEach<This>(
4+
forEach<This = undefined>(
55
callbackfn: (this: This, value: V, key: K, map: Map<K, V>) => void,
66
thisArg?: This
77
): void;
@@ -26,15 +26,15 @@ interface WeakMap<K extends object, V> {
2626
}
2727

2828
interface WeakMapConstructor {
29-
new <K extends object = object, V = unknown>(
30-
entries?: readonly [K, V][] | null
29+
new <K extends object, V>(
30+
entries?: readonly (readonly [K, V])[] | null
3131
): WeakMap<K, V>;
3232
readonly prototype: WeakMap<object, unknown>;
3333
}
3434
declare var WeakMap: WeakMapConstructor;
3535

3636
interface ReadonlyMap<K, V> {
37-
forEach<This>(
37+
forEach<This = undefined>(
3838
callbackfn: (this: This, value: V, key: K, map: ReadonlyMap<K, V>) => void,
3939
thisArg?: This
4040
): void;
@@ -47,7 +47,7 @@ interface Set<T> {
4747
add(value: T): this;
4848
clear(): void;
4949
delete(value: T): boolean;
50-
forEach<This>(
50+
forEach<This = undefined>(
5151
callbackfn: (this: This, value: T, value2: T, set: Set<T>) => void,
5252
thisArg?: This
5353
): void;
@@ -62,7 +62,7 @@ interface SetConstructor {
6262
declare var Set: SetConstructor;
6363

6464
interface ReadonlySet<T> {
65-
forEach<This>(
65+
forEach<This = undefined>(
6666
callbackfn: (this: This, value: T, value2: T, set: ReadonlySet<T>) => void,
6767
thisArg?: This
6868
): void;

lib/lib.es5.d.ts

+74-44
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,14 @@ interface ReadonlyArray<T> {
423423
* @param thisArg An object to which the this keyword can refer in the predicate function.
424424
* If thisArg is omitted, undefined is used as the this value.
425425
*/
426-
every<S extends T>(
427-
predicate: (value: T, index: number, array: readonly T[]) => value is S,
428-
thisArg?: any
426+
every<S extends T, This = undefined>(
427+
predicate: (
428+
this: This,
429+
value: T,
430+
index: number,
431+
array: readonly T[]
432+
) => value is S,
433+
thisArg?: This
429434
): this is readonly S[];
430435
/**
431436
* Determines whether all the members of an array satisfy the specified test.
@@ -435,9 +440,14 @@ interface ReadonlyArray<T> {
435440
* @param thisArg An object to which the this keyword can refer in the predicate function.
436441
* If thisArg is omitted, undefined is used as the this value.
437442
*/
438-
every(
439-
predicate: (value: T, index: number, array: readonly T[]) => boolean,
440-
thisArg?: any
443+
every<This = undefined>(
444+
predicate: (
445+
this: This,
446+
value: T,
447+
index: number,
448+
array: readonly T[]
449+
) => boolean,
450+
thisArg?: This
441451
): boolean;
442452
/**
443453
* Determines whether the specified callback function returns true for any element of an array.
@@ -447,45 +457,65 @@ interface ReadonlyArray<T> {
447457
* @param thisArg An object to which the this keyword can refer in the predicate function.
448458
* If thisArg is omitted, undefined is used as the this value.
449459
*/
450-
some(
451-
predicate: (value: T, index: number, array: readonly T[]) => boolean,
452-
thisArg?: any
460+
some<This = undefined>(
461+
predicate: (
462+
this: This,
463+
value: T,
464+
index: number,
465+
array: readonly T[]
466+
) => boolean,
467+
thisArg?: This
453468
): boolean;
454469
/**
455470
* Performs the specified action for each element in an array.
456471
* @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
457472
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
458473
*/
459-
forEach(
460-
callbackfn: (value: T, index: number, array: readonly T[]) => void,
461-
thisArg?: any
474+
forEach<This = undefined>(
475+
callbackfn: (
476+
this: This,
477+
value: T,
478+
index: number,
479+
array: readonly T[]
480+
) => void,
481+
thisArg?: This
462482
): void;
463483
/**
464484
* Calls a defined callback function on each element of an array, and returns an array that contains the results.
465485
* @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
466486
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
467487
*/
468-
map<U>(
469-
callbackfn: (value: T, index: number, array: readonly T[]) => U,
470-
thisArg?: any
488+
map<U, This = undefined>(
489+
callbackfn: (this: This, value: T, index: number, array: readonly T[]) => U,
490+
thisArg?: This
471491
): U[];
472492
/**
473493
* Returns the elements of an array that meet the condition specified in a callback function.
474494
* @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
475495
* @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
476496
*/
477-
filter<S extends T>(
478-
predicate: (value: T, index: number, array: readonly T[]) => value is S,
479-
thisArg?: any
497+
filter<S extends T, This = undefined>(
498+
predicate: (
499+
this: This,
500+
value: T,
501+
index: number,
502+
array: readonly T[]
503+
) => value is S,
504+
thisArg?: This
480505
): S[];
481506
/**
482507
* Returns the elements of an array that meet the condition specified in a callback function.
483508
* @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
484509
* @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
485510
*/
486-
filter(
487-
predicate: (value: T, index: number, array: readonly T[]) => boolean,
488-
thisArg?: any
511+
filter<This = undefined>(
512+
predicate: (
513+
this: This,
514+
value: T,
515+
index: number,
516+
array: readonly T[]
517+
) => boolean,
518+
thisArg?: This
489519
): T[];
490520
/**
491521
* Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
@@ -640,15 +670,15 @@ interface Array<T> {
640670
* @param deleteCount The number of elements to remove.
641671
* @returns An array containing the elements that were deleted.
642672
*/
643-
splice(start: number, deleteCount?: number): T[];
673+
splice(start: number, deleteCount?: number): this;
644674
/**
645675
* Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
646676
* @param start The zero-based location in the array from which to start removing elements.
647677
* @param deleteCount The number of elements to remove.
648678
* @param items Elements to insert into the array in place of the deleted elements.
649679
* @returns An array containing the elements that were deleted.
650680
*/
651-
splice(start: number, deleteCount: number, ...items: T[]): T[];
681+
splice(start: number, deleteCount: number, ...items: T[]): this;
652682
/**
653683
* Inserts new elements at the start of an array, and returns the new length of the array.
654684
* @param items Elements to insert at the start of the array.
@@ -674,9 +704,9 @@ interface Array<T> {
674704
* @param thisArg An object to which the this keyword can refer in the predicate function.
675705
* If thisArg is omitted, undefined is used as the this value.
676706
*/
677-
every<S extends T>(
678-
predicate: (value: T, index: number, array: T[]) => value is S,
679-
thisArg?: any
707+
every<S extends T, This = undefined>(
708+
predicate: (this: This, value: T, index: number, array: T[]) => value is S,
709+
thisArg?: This
680710
): this is S[];
681711
/**
682712
* Determines whether all the members of an array satisfy the specified test.
@@ -686,9 +716,9 @@ interface Array<T> {
686716
* @param thisArg An object to which the this keyword can refer in the predicate function.
687717
* If thisArg is omitted, undefined is used as the this value.
688718
*/
689-
every(
690-
predicate: (value: T, index: number, array: T[]) => boolean,
691-
thisArg?: any
719+
every<This = undefined>(
720+
predicate: (this: This, value: T, index: number, array: T[]) => boolean,
721+
thisArg?: This
692722
): boolean;
693723
/**
694724
* Determines whether the specified callback function returns true for any element of an array.
@@ -698,45 +728,45 @@ interface Array<T> {
698728
* @param thisArg An object to which the this keyword can refer in the predicate function.
699729
* If thisArg is omitted, undefined is used as the this value.
700730
*/
701-
some(
702-
predicate: (value: T, index: number, array: T[]) => boolean,
703-
thisArg?: any
731+
some<This = undefined>(
732+
predicate: (this: This, value: T, index: number, array: T[]) => boolean,
733+
thisArg?: This
704734
): boolean;
705735
/**
706736
* Performs the specified action for each element in an array.
707737
* @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
708738
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
709739
*/
710-
forEach(
711-
callbackfn: (value: T, index: number, array: T[]) => void,
712-
thisArg?: any
740+
forEach<This = undefined>(
741+
callbackfn: (this: This, value: T, index: number, array: T[]) => void,
742+
thisArg?: This
713743
): void;
714744
/**
715745
* Calls a defined callback function on each element of an array, and returns an array that contains the results.
716746
* @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
717747
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
718748
*/
719-
map<U>(
720-
callbackfn: (value: T, index: number, array: T[]) => U,
721-
thisArg?: any
749+
map<U, This = undefined>(
750+
callbackfn: (this: This, value: T, index: number, array: T[]) => U,
751+
thisArg?: This
722752
): U[];
723753
/**
724754
* Returns the elements of an array that meet the condition specified in a callback function.
725755
* @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
726756
* @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
727757
*/
728-
filter<S extends T>(
729-
predicate: (value: T, index: number, array: T[]) => value is S,
730-
thisArg?: any
758+
filter<S extends T, This = undefined>(
759+
predicate: (this: This, value: T, index: number, array: T[]) => value is S,
760+
thisArg?: This
731761
): S[];
732762
/**
733763
* Returns the elements of an array that meet the condition specified in a callback function.
734764
* @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
735765
* @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
736766
*/
737-
filter(
738-
predicate: (value: T, index: number, array: T[]) => boolean,
739-
thisArg?: any
767+
filter<This = undefined>(
768+
predicate: (this: This, value: T, index: number, array: T[]) => boolean,
769+
thisArg?: This
740770
): T[];
741771
/**
742772
* Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

0 commit comments

Comments
 (0)