mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
@@ -18,15 +18,9 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covarian
|
||||
Types of property 'forEach' are incompatible.
|
||||
Type '(cb: (item: A) => void) => void' is not assignable to type '(cb: (item: A, context: any) => void) => void'.
|
||||
Types of parameters 'cb' and 'cb' are incompatible.
|
||||
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts(69,5): error TS2322: Type 'AList4' is not assignable to type 'BList4'.
|
||||
Types of property 'forEach' are incompatible.
|
||||
Type '(cb: (item: A) => A) => void' is not assignable to type '(cb: (item: B) => B) => void'.
|
||||
Types of parameters 'cb' and 'cb' are incompatible.
|
||||
Types of parameters 'item' and 'item' are incompatible.
|
||||
Type 'A' is not assignable to type 'B'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts (6 errors) ====
|
||||
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts (5 errors) ====
|
||||
// Test that callback parameters are related covariantly
|
||||
|
||||
interface P<T> {
|
||||
@@ -108,25 +102,4 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covarian
|
||||
!!! error TS2322: Types of property 'forEach' are incompatible.
|
||||
!!! error TS2322: Type '(cb: (item: A) => void) => void' is not assignable to type '(cb: (item: A, context: any) => void) => void'.
|
||||
!!! error TS2322: Types of parameters 'cb' and 'cb' are incompatible.
|
||||
}
|
||||
|
||||
interface AList4 {
|
||||
forEach(cb: (item: A) => A): void;
|
||||
}
|
||||
|
||||
interface BList4 {
|
||||
forEach(cb: (item: B) => B): void;
|
||||
}
|
||||
|
||||
function f14(a: AList4, b: BList4) {
|
||||
a = b;
|
||||
b = a; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'AList4' is not assignable to type 'BList4'.
|
||||
!!! error TS2322: Types of property 'forEach' are incompatible.
|
||||
!!! error TS2322: Type '(cb: (item: A) => A) => void' is not assignable to type '(cb: (item: B) => B) => void'.
|
||||
!!! error TS2322: Types of parameters 'cb' and 'cb' are incompatible.
|
||||
!!! error TS2322: Types of parameters 'item' and 'item' are incompatible.
|
||||
!!! error TS2322: Type 'A' is not assignable to type 'B'.
|
||||
}
|
||||
|
||||
}
|
||||
@@ -55,21 +55,7 @@ interface BList3 {
|
||||
function f13(a: AList3, b: BList3) {
|
||||
a = b;
|
||||
b = a; // Error
|
||||
}
|
||||
|
||||
interface AList4 {
|
||||
forEach(cb: (item: A) => A): void;
|
||||
}
|
||||
|
||||
interface BList4 {
|
||||
forEach(cb: (item: B) => B): void;
|
||||
}
|
||||
|
||||
function f14(a: AList4, b: BList4) {
|
||||
a = b;
|
||||
b = a; // Error
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//// [covariantCallbacks.js]
|
||||
// Test that callback parameters are related covariantly
|
||||
@@ -94,7 +80,3 @@ function f13(a, b) {
|
||||
a = b;
|
||||
b = a; // Error
|
||||
}
|
||||
function f14(a, b) {
|
||||
a = b;
|
||||
b = a; // Error
|
||||
}
|
||||
|
||||
+1
-14
@@ -56,17 +56,4 @@ interface BList3 {
|
||||
function f13(a: AList3, b: BList3) {
|
||||
a = b;
|
||||
b = a; // Error
|
||||
}
|
||||
|
||||
interface AList4 {
|
||||
forEach(cb: (item: A) => A): void;
|
||||
}
|
||||
|
||||
interface BList4 {
|
||||
forEach(cb: (item: B) => B): void;
|
||||
}
|
||||
|
||||
function f14(a: AList4, b: BList4) {
|
||||
a = b;
|
||||
b = a; // Error
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user