Skip to content

Commit 510bc81

Browse files
committed
Add another test case
1 parent 33bc9d1 commit 510bc81

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

tests/baselines/reference/covariantCallbacks.errors.txt

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covarian
1818
Types of property 'forEach' are incompatible.
1919
Type '(cb: (item: A) => void) => void' is not assignable to type '(cb: (item: A, context: any) => void) => void'.
2020
Types of parameters 'cb' and 'cb' are incompatible.
21+
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts(69,5): error TS2322: Type 'AList4' is not assignable to type 'BList4'.
22+
Types of property 'forEach' are incompatible.
23+
Type '(cb: (item: A) => A) => void' is not assignable to type '(cb: (item: B) => B) => void'.
24+
Types of parameters 'cb' and 'cb' are incompatible.
25+
Types of parameters 'item' and 'item' are incompatible.
26+
Type 'A' is not assignable to type 'B'.
2127

2228

23-
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts (5 errors) ====
29+
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts (6 errors) ====
2430
// Test that callback parameters are related covariantly
2531

2632
interface P<T> {
@@ -102,4 +108,25 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covarian
102108
!!! error TS2322: Types of property 'forEach' are incompatible.
103109
!!! error TS2322: Type '(cb: (item: A) => void) => void' is not assignable to type '(cb: (item: A, context: any) => void) => void'.
104110
!!! error TS2322: Types of parameters 'cb' and 'cb' are incompatible.
105-
}
111+
}
112+
113+
interface AList4 {
114+
forEach(cb: (item: A) => A): void;
115+
}
116+
117+
interface BList4 {
118+
forEach(cb: (item: B) => B): void;
119+
}
120+
121+
function f14(a: AList4, b: BList4) {
122+
a = b;
123+
b = a; // Error
124+
~
125+
!!! error TS2322: Type 'AList4' is not assignable to type 'BList4'.
126+
!!! error TS2322: Types of property 'forEach' are incompatible.
127+
!!! error TS2322: Type '(cb: (item: A) => A) => void' is not assignable to type '(cb: (item: B) => B) => void'.
128+
!!! error TS2322: Types of parameters 'cb' and 'cb' are incompatible.
129+
!!! error TS2322: Types of parameters 'item' and 'item' are incompatible.
130+
!!! error TS2322: Type 'A' is not assignable to type 'B'.
131+
}
132+

tests/baselines/reference/covariantCallbacks.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,21 @@ interface BList3 {
5555
function f13(a: AList3, b: BList3) {
5656
a = b;
5757
b = a; // Error
58-
}
58+
}
59+
60+
interface AList4 {
61+
forEach(cb: (item: A) => A): void;
62+
}
63+
64+
interface BList4 {
65+
forEach(cb: (item: B) => B): void;
66+
}
67+
68+
function f14(a: AList4, b: BList4) {
69+
a = b;
70+
b = a; // Error
71+
}
72+
5973

6074
//// [covariantCallbacks.js]
6175
// Test that callback parameters are related covariantly
@@ -80,3 +94,7 @@ function f13(a, b) {
8094
a = b;
8195
b = a; // Error
8296
}
97+
function f14(a, b) {
98+
a = b;
99+
b = a; // Error
100+
}

tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,17 @@ interface BList3 {
5656
function f13(a: AList3, b: BList3) {
5757
a = b;
5858
b = a; // Error
59-
}
59+
}
60+
61+
interface AList4 {
62+
forEach(cb: (item: A) => A): void;
63+
}
64+
65+
interface BList4 {
66+
forEach(cb: (item: B) => B): void;
67+
}
68+
69+
function f14(a: AList4, b: BList4) {
70+
a = b;
71+
b = a; // Error
72+
}

0 commit comments

Comments
 (0)