Skip to content

Commit c74dcb6

Browse files
committed
Fix Array interface (microsoft#10886)
1 parent 381960f commit c74dcb6

15 files changed

+147
-161
lines changed

src/lib/es2015.core.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ 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: (value: T, index: number, obj: this) => boolean, thisArg?: any): T | undefined;
1414

1515
/**
1616
* Returns the index of the first element in the array where predicate is true, and -1
@@ -21,7 +21,7 @@ interface Array<T> {
2121
* @param thisArg If provided, it will be used as the this value for each invocation of
2222
* predicate. If it is not provided, undefined is used instead.
2323
*/
24-
findIndex(predicate: (value: T, index: number, obj: Array<T>) => boolean, thisArg?: any): number;
24+
findIndex(predicate: (value: T, index: number, obj: this) => boolean, thisArg?: any): number;
2525

2626
/**
2727
* Returns the this object after filling the section identified by start and end with value

src/lib/es5.d.ts

Lines changed: 33 additions & 33 deletions
Large diffs are not rendered by default.
Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(13,1): error TS2322: Type 'A[]' is not assignable to type 'ReadonlyArray<B>'.
2-
Types of property 'concat' are incompatible.
3-
Type '{ (...items: A[][]): A[]; (...items: (A | A[])[]): A[]; }' is not assignable to type '{ <U extends ReadonlyArray<B>>(...items: U[]): B[]; (...items: B[][]): B[]; (...items: (B | B[])[]): B[]; }'.
4-
Type 'A[]' is not assignable to type 'B[]'.
5-
Type 'A' is not assignable to type 'B'.
6-
Property 'b' is missing in type 'A'.
2+
Index signatures are incompatible.
3+
Type 'A' is not assignable to type 'B'.
74
tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(18,1): error TS2322: Type 'C<A>' is not assignable to type 'ReadonlyArray<B>'.
8-
Types of property 'concat' are incompatible.
9-
Type '{ (...items: A[][]): A[]; (...items: (A | A[])[]): A[]; }' is not assignable to type '{ <U extends ReadonlyArray<B>>(...items: U[]): B[]; (...items: B[][]): B[]; (...items: (B | B[])[]): B[]; }'.
10-
Type 'A[]' is not assignable to type 'B[]'.
11-
Type 'A' is not assignable to type 'B'.
5+
Index signatures are incompatible.
6+
Type 'A' is not assignable to type 'B'.
127

138

149
==== tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts (2 errors) ====
@@ -27,20 +22,15 @@ tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(18,1): error T
2722
rrb = ara; // error: 'A' is not assignable to 'B'
2823
~~~
2924
!!! error TS2322: Type 'A[]' is not assignable to type 'ReadonlyArray<B>'.
30-
!!! error TS2322: Types of property 'concat' are incompatible.
31-
!!! error TS2322: Type '{ (...items: A[][]): A[]; (...items: (A | A[])[]): A[]; }' is not assignable to type '{ <U extends ReadonlyArray<B>>(...items: U[]): B[]; (...items: B[][]): B[]; (...items: (B | B[])[]): B[]; }'.
32-
!!! error TS2322: Type 'A[]' is not assignable to type 'B[]'.
33-
!!! error TS2322: Type 'A' is not assignable to type 'B'.
34-
!!! error TS2322: Property 'b' is missing in type 'A'.
25+
!!! error TS2322: Index signatures are incompatible.
26+
!!! error TS2322: Type 'A' is not assignable to type 'B'.
3527

3628
rra = cra;
3729
rra = crb; // OK, C<B> is assignable to ReadonlyArray<A>
3830
rrb = crb;
3931
rrb = cra; // error: 'A' is not assignable to 'B'
4032
~~~
4133
!!! error TS2322: Type 'C<A>' is not assignable to type 'ReadonlyArray<B>'.
42-
!!! error TS2322: Types of property 'concat' are incompatible.
43-
!!! error TS2322: Type '{ (...items: A[][]): A[]; (...items: (A | A[])[]): A[]; }' is not assignable to type '{ <U extends ReadonlyArray<B>>(...items: U[]): B[]; (...items: B[][]): B[]; (...items: (B | B[])[]): B[]; }'.
44-
!!! error TS2322: Type 'A[]' is not assignable to type 'B[]'.
45-
!!! error TS2322: Type 'A' is not assignable to type 'B'.
34+
!!! error TS2322: Index signatures are incompatible.
35+
!!! error TS2322: Type 'A' is not assignable to type 'B'.
4636

tests/baselines/reference/bestChoiceType.types

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
(''.match(/ /) || []).map(s => s.toLowerCase());
66
>(''.match(/ /) || []).map(s => s.toLowerCase()) : string[]
7-
>(''.match(/ /) || []).map : { <U>(this: [string, string, string, string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U, U, U, U]; <U>(this: [string, string, string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U, U, U]; <U>(this: [string, string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U, U]; <U>(this: [string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U]; <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): U[]; }
7+
>(''.match(/ /) || []).map : { <U>(this: [string, string, string, string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U, U, U, U]; <U>(this: [string, string, string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U, U, U]; <U>(this: [string, string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U, U]; <U>(this: [string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U]; <U>(callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): U[]; }
88
>(''.match(/ /) || []) : RegExpMatchArray
99
>''.match(/ /) || [] : RegExpMatchArray
1010
>''.match(/ /) : RegExpMatchArray | null
@@ -13,7 +13,7 @@
1313
>match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; }
1414
>/ / : RegExp
1515
>[] : never[]
16-
>map : { <U>(this: [string, string, string, string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U, U, U, U]; <U>(this: [string, string, string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U, U, U]; <U>(this: [string, string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U, U]; <U>(this: [string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U]; <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): U[]; }
16+
>map : { <U>(this: [string, string, string, string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U, U, U, U]; <U>(this: [string, string, string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U, U, U]; <U>(this: [string, string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U, U]; <U>(this: [string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U]; <U>(callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): U[]; }
1717
>s => s.toLowerCase() : (s: string) => string
1818
>s : string
1919
>s.toLowerCase() : string
@@ -43,9 +43,9 @@ function f1() {
4343
let z = y.map(s => s.toLowerCase());
4444
>z : string[]
4545
>y.map(s => s.toLowerCase()) : string[]
46-
>y.map : { <U>(this: [string, string, string, string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U, U, U, U]; <U>(this: [string, string, string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U, U, U]; <U>(this: [string, string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U, U]; <U>(this: [string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U]; <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): U[]; }
46+
>y.map : { <U>(this: [string, string, string, string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U, U, U, U]; <U>(this: [string, string, string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U, U, U]; <U>(this: [string, string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U, U]; <U>(this: [string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U]; <U>(callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): U[]; }
4747
>y : RegExpMatchArray
48-
>map : { <U>(this: [string, string, string, string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U, U, U, U]; <U>(this: [string, string, string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U, U, U]; <U>(this: [string, string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U, U]; <U>(this: [string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U]; <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): U[]; }
48+
>map : { <U>(this: [string, string, string, string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U, U, U, U]; <U>(this: [string, string, string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U, U, U]; <U>(this: [string, string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U, U]; <U>(this: [string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U]; <U>(callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): U[]; }
4949
>s => s.toLowerCase() : (s: string) => string
5050
>s : string
5151
>s.toLowerCase() : string
@@ -75,9 +75,9 @@ function f2() {
7575
let z = y.map(s => s.toLowerCase());
7676
>z : string[]
7777
>y.map(s => s.toLowerCase()) : string[]
78-
>y.map : { <U>(this: [string, string, string, string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U, U, U, U]; <U>(this: [string, string, string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U, U, U]; <U>(this: [string, string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U, U]; <U>(this: [string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U]; <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): U[]; }
78+
>y.map : { <U>(this: [string, string, string, string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U, U, U, U]; <U>(this: [string, string, string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U, U, U]; <U>(this: [string, string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U, U]; <U>(this: [string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U]; <U>(callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): U[]; }
7979
>y : RegExpMatchArray
80-
>map : { <U>(this: [string, string, string, string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U, U, U, U]; <U>(this: [string, string, string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U, U, U]; <U>(this: [string, string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U, U]; <U>(this: [string, string], callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): [U, U]; <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): U[]; }
80+
>map : { <U>(this: [string, string, string, string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U, U, U, U]; <U>(this: [string, string, string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U, U, U]; <U>(this: [string, string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U, U]; <U>(this: [string, string], callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): [U, U]; <U>(callbackfn: (value: string, index: number, array: RegExpMatchArray) => U, thisArg?: any): U[]; }
8181
>s => s.toLowerCase() : (s: string) => string
8282
>s : string
8383
>s.toLowerCase() : string

tests/baselines/reference/duplicateOverloadInTypeAugmentation1.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//// [duplicateOverloadInTypeAugmentation1.ts]
22
interface Array<T> {
3-
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T,
3+
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: this) => T,
44
initialValue?: T): T;
5-
reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U,
5+
reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: this) => U,
66
initialValue: U): U;
77
}
88
var a: Array<string>;

tests/baselines/reference/duplicateOverloadInTypeAugmentation1.symbols

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ interface Array<T> {
33
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 0))
44
>T : Symbol(T, Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 16))
55

6-
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T,
6+
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: this) => T,
77
>reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 20), Decl(duplicateOverloadInTypeAugmentation1.ts, 2, 29))
88
>callbackfn : Symbol(callbackfn, Decl(duplicateOverloadInTypeAugmentation1.ts, 1, 11))
99
>previousValue : Symbol(previousValue, Decl(duplicateOverloadInTypeAugmentation1.ts, 1, 24))
@@ -12,15 +12,14 @@ interface Array<T> {
1212
>T : Symbol(T, Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 16))
1313
>currentIndex : Symbol(currentIndex, Decl(duplicateOverloadInTypeAugmentation1.ts, 1, 58))
1414
>array : Symbol(array, Decl(duplicateOverloadInTypeAugmentation1.ts, 1, 80))
15-
>T : Symbol(T, Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 16))
1615
>T : Symbol(T, Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 16))
1716

1817
initialValue?: T): T;
19-
>initialValue : Symbol(initialValue, Decl(duplicateOverloadInTypeAugmentation1.ts, 1, 98))
18+
>initialValue : Symbol(initialValue, Decl(duplicateOverloadInTypeAugmentation1.ts, 1, 99))
2019
>T : Symbol(T, Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 16))
2120
>T : Symbol(T, Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 16))
2221

23-
reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U,
22+
reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: this) => U,
2423
>reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 20), Decl(duplicateOverloadInTypeAugmentation1.ts, 2, 29))
2524
>U : Symbol(U, Decl(duplicateOverloadInTypeAugmentation1.ts, 3, 11))
2625
>callbackfn : Symbol(callbackfn, Decl(duplicateOverloadInTypeAugmentation1.ts, 3, 14))
@@ -30,11 +29,10 @@ interface Array<T> {
3029
>T : Symbol(T, Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 16))
3130
>currentIndex : Symbol(currentIndex, Decl(duplicateOverloadInTypeAugmentation1.ts, 3, 61))
3231
>array : Symbol(array, Decl(duplicateOverloadInTypeAugmentation1.ts, 3, 83))
33-
>T : Symbol(T, Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 16))
3432
>U : Symbol(U, Decl(duplicateOverloadInTypeAugmentation1.ts, 3, 11))
3533

3634
initialValue: U): U;
37-
>initialValue : Symbol(initialValue, Decl(duplicateOverloadInTypeAugmentation1.ts, 3, 101))
35+
>initialValue : Symbol(initialValue, Decl(duplicateOverloadInTypeAugmentation1.ts, 3, 102))
3836
>U : Symbol(U, Decl(duplicateOverloadInTypeAugmentation1.ts, 3, 11))
3937
>U : Symbol(U, Decl(duplicateOverloadInTypeAugmentation1.ts, 3, 11))
4038
}

tests/baselines/reference/duplicateOverloadInTypeAugmentation1.types

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,32 @@ interface Array<T> {
33
>Array : T[]
44
>T : T
55

6-
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T,
7-
>reduce : { (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; }
8-
>callbackfn : (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T
6+
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: this) => T,
7+
>reduce : { (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: this) => T, initialValue?: T): T; <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: this) => U, initialValue: U): U; (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: this) => T, initialValue?: T): T; <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: this) => U, initialValue: U): U; }
8+
>callbackfn : (previousValue: T, currentValue: T, currentIndex: number, array: this) => T
99
>previousValue : T
1010
>T : T
1111
>currentValue : T
1212
>T : T
1313
>currentIndex : number
14-
>array : T[]
15-
>T : T
14+
>array : this
1615
>T : T
1716

1817
initialValue?: T): T;
1918
>initialValue : T
2019
>T : T
2120
>T : T
2221

23-
reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U,
24-
>reduce : { (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; }
22+
reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: this) => U,
23+
>reduce : { (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: this) => T, initialValue?: T): T; <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: this) => U, initialValue: U): U; (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: this) => T, initialValue?: T): T; <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: this) => U, initialValue: U): U; }
2524
>U : U
26-
>callbackfn : (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U
25+
>callbackfn : (previousValue: U, currentValue: T, currentIndex: number, array: this) => U
2726
>previousValue : U
2827
>U : U
2928
>currentValue : T
3029
>T : T
3130
>currentIndex : number
32-
>array : T[]
33-
>T : T
31+
>array : this
3432
>U : U
3533

3634
initialValue: U): U;

0 commit comments

Comments
 (0)