Skip to content

Commit 84ea509

Browse files
committed
fix: add generic info for methods with thisArg of built-in classes
when enabling `noImplicitThis`, if assing this argument for methods like `array.forEach` will cause compilation error. This commit fixes it. fix #12548
1 parent 9a62db2 commit 84ea509

File tree

3 files changed

+390
-150
lines changed

3 files changed

+390
-150
lines changed

src/lib/es2015.core.d.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ interface Array<T> {
1010
* @param thisArg If provided, it will be used as the this value for each invocation of
1111
* predicate. If it is not provided, undefined is used instead.
1212
*/
13-
find(predicate: (value: T, index: number, obj: Array<T>) => boolean, thisArg?: any): T | undefined;
13+
find(predicate: (this: undefined, value: T, index: number, obj: Array<T>) => boolean): T | undefined;
14+
find(predicate: (this: undefined, value: T, index: number, obj: Array<T>) => boolean, thisArg: undefined): T | undefined;
15+
find<Z>(predicate: (this: Z, value: T, index: number, obj: Array<T>) => boolean, thisArg: Z): T | undefined;
1416

1517
/**
1618
* Returns the index of the first element in the array where predicate is true, and -1
@@ -21,7 +23,9 @@ interface Array<T> {
2123
* @param thisArg If provided, it will be used as the this value for each invocation of
2224
* predicate. If it is not provided, undefined is used instead.
2325
*/
24-
findIndex(predicate: (value: T, index: number, obj: Array<T>) => boolean, thisArg?: any): number;
26+
findIndex(predicate: (this: undefined, value: T, index: number, obj: Array<T>) => boolean): number;
27+
findIndex(predicate: (this: undefined, value: T, index: number, obj: Array<T>) => boolean, thisArg: undefined): number;
28+
findIndex<Z>(predicate: (this: Z, value: T, index: number, obj: Array<T>) => boolean, thisArg: Z): number;
2529

2630
/**
2731
* Returns the this object after filling the section identified by start and end with value
@@ -52,7 +56,9 @@ interface ArrayConstructor {
5256
* @param mapfn A mapping function to call on every element of the array.
5357
* @param thisArg Value of 'this' used to invoke the mapfn.
5458
*/
55-
from<T, U>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): Array<U>;
59+
from<T, U>(arrayLike: ArrayLike<T>, mapfn: (this: undefined, v: T, k: number) => U): Array<U>;
60+
from<T, U>(arrayLike: ArrayLike<T>, mapfn: (this: undefined, v: T, k: number) => U, thisArg: undefined): Array<U>;
61+
from<Z, T, U>(arrayLike: ArrayLike<T>, mapfn: (this: Z, v: T, k: number) => U, thisArg: Z): Array<U>;
5662

5763

5864
/**
@@ -357,7 +363,9 @@ interface ReadonlyArray<T> {
357363
* @param thisArg If provided, it will be used as the this value for each invocation of
358364
* predicate. If it is not provided, undefined is used instead.
359365
*/
360-
find(predicate: (value: T, index: number, obj: ReadonlyArray<T>) => boolean, thisArg?: any): T | undefined;
366+
find(predicate: (this: undefined, value: T, index: number, obj: ReadonlyArray<T>) => boolean): T | undefined;
367+
find(predicate: (this: undefined, value: T, index: number, obj: ReadonlyArray<T>) => boolean, thisArg: undefined): T | undefined;
368+
find<Z>(predicate: (this: Z, value: T, index: number, obj: ReadonlyArray<T>) => boolean, thisArg: Z): T | undefined;
361369

362370
/**
363371
* Returns the index of the first element in the array where predicate is true, and -1
@@ -368,7 +376,9 @@ interface ReadonlyArray<T> {
368376
* @param thisArg If provided, it will be used as the this value for each invocation of
369377
* predicate. If it is not provided, undefined is used instead.
370378
*/
371-
findIndex(predicate: (value: T, index: number, obj: Array<T>) => boolean, thisArg?: any): number;
379+
findIndex(predicate: (this: undefined, value: T, index: number, obj: Array<T>) => boolean): number;
380+
findIndex(predicate: (this: undefined, value: T, index: number, obj: Array<T>) => boolean, thisArg: undefined): number;
381+
findIndex<Z>(predicate: (this: Z, value: T, index: number, obj: Array<T>) => boolean, thisArg: Z): number;
372382
}
373383

374384
interface RegExp {

0 commit comments

Comments
 (0)