|
| 1 | +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts(12,5): error TS2322: Type 'P<A>' is not assignable to type 'P<B>'. |
| 2 | + Type 'A' is not assignable to type 'B'. |
| 3 | + Property 'b' is missing in type 'A'. |
| 4 | +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts(17,5): error TS2322: Type 'Promise<A>' is not assignable to type 'Promise<B>'. |
| 5 | + Type 'A' is not assignable to type 'B'. |
| 6 | +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts(30,5): error TS2322: Type 'AList1' is not assignable to type 'BList1'. |
| 7 | + Types of property 'forEach' are incompatible. |
| 8 | + Type '(cb: (item: A) => void) => void' is not assignable to type '(cb: (item: B) => void) => void'. |
| 9 | + Types of parameters 'cb' and 'cb' are incompatible. |
| 10 | + Types of parameters 'item' and 'item' are incompatible. |
| 11 | + Type 'A' is not assignable to type 'B'. |
| 12 | +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts(43,5): error TS2322: Type 'AList2' is not assignable to type 'BList2'. |
| 13 | + Types of property 'forEach' are incompatible. |
| 14 | + Type '(cb: (item: A) => boolean) => void' is not assignable to type '(cb: (item: A) => void) => void'. |
| 15 | + Types of parameters 'cb' and 'cb' are incompatible. |
| 16 | + Type 'void' is not assignable to type 'boolean'. |
| 17 | +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts(56,5): error TS2322: Type 'AList3' is not assignable to type 'BList3'. |
| 18 | + Types of property 'forEach' are incompatible. |
| 19 | + Type '(cb: (item: A) => void) => void' is not assignable to type '(cb: (item: A, context: any) => void) => void'. |
| 20 | + Types of parameters 'cb' and 'cb' are incompatible. |
| 21 | + |
| 22 | + |
| 23 | +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts (5 errors) ==== |
| 24 | + // Test that callback parameters are related covariantly |
| 25 | + |
| 26 | + interface P<T> { |
| 27 | + then(cb: (value: T) => void): void; |
| 28 | + }; |
| 29 | + |
| 30 | + interface A { a: string } |
| 31 | + interface B extends A { b: string } |
| 32 | + |
| 33 | + function f1(a: P<A>, b: P<B>) { |
| 34 | + a = b; |
| 35 | + b = a; // Error |
| 36 | + ~ |
| 37 | +!!! error TS2322: Type 'P<A>' is not assignable to type 'P<B>'. |
| 38 | +!!! error TS2322: Type 'A' is not assignable to type 'B'. |
| 39 | +!!! error TS2322: Property 'b' is missing in type 'A'. |
| 40 | + } |
| 41 | + |
| 42 | + function f2(a: Promise<A>, b: Promise<B>) { |
| 43 | + a = b; |
| 44 | + b = a; // Error |
| 45 | + ~ |
| 46 | +!!! error TS2322: Type 'Promise<A>' is not assignable to type 'Promise<B>'. |
| 47 | +!!! error TS2322: Type 'A' is not assignable to type 'B'. |
| 48 | + } |
| 49 | + |
| 50 | + interface AList1 { |
| 51 | + forEach(cb: (item: A) => void): void; |
| 52 | + } |
| 53 | + |
| 54 | + interface BList1 { |
| 55 | + forEach(cb: (item: B) => void): void; |
| 56 | + } |
| 57 | + |
| 58 | + function f11(a: AList1, b: BList1) { |
| 59 | + a = b; |
| 60 | + b = a; // Error |
| 61 | + ~ |
| 62 | +!!! error TS2322: Type 'AList1' is not assignable to type 'BList1'. |
| 63 | +!!! error TS2322: Types of property 'forEach' are incompatible. |
| 64 | +!!! error TS2322: Type '(cb: (item: A) => void) => void' is not assignable to type '(cb: (item: B) => void) => void'. |
| 65 | +!!! error TS2322: Types of parameters 'cb' and 'cb' are incompatible. |
| 66 | +!!! error TS2322: Types of parameters 'item' and 'item' are incompatible. |
| 67 | +!!! error TS2322: Type 'A' is not assignable to type 'B'. |
| 68 | + } |
| 69 | + |
| 70 | + interface AList2 { |
| 71 | + forEach(cb: (item: A) => boolean): void; |
| 72 | + } |
| 73 | + |
| 74 | + interface BList2 { |
| 75 | + forEach(cb: (item: A) => void): void; |
| 76 | + } |
| 77 | + |
| 78 | + function f12(a: AList2, b: BList2) { |
| 79 | + a = b; |
| 80 | + b = a; // Error |
| 81 | + ~ |
| 82 | +!!! error TS2322: Type 'AList2' is not assignable to type 'BList2'. |
| 83 | +!!! error TS2322: Types of property 'forEach' are incompatible. |
| 84 | +!!! error TS2322: Type '(cb: (item: A) => boolean) => void' is not assignable to type '(cb: (item: A) => void) => void'. |
| 85 | +!!! error TS2322: Types of parameters 'cb' and 'cb' are incompatible. |
| 86 | +!!! error TS2322: Type 'void' is not assignable to type 'boolean'. |
| 87 | + } |
| 88 | + |
| 89 | + interface AList3 { |
| 90 | + forEach(cb: (item: A) => void): void; |
| 91 | + } |
| 92 | + |
| 93 | + interface BList3 { |
| 94 | + forEach(cb: (item: A, context: any) => void): void; |
| 95 | + } |
| 96 | + |
| 97 | + function f13(a: AList3, b: BList3) { |
| 98 | + a = b; |
| 99 | + b = a; // Error |
| 100 | + ~ |
| 101 | +!!! error TS2322: Type 'AList3' is not assignable to type 'BList3'. |
| 102 | +!!! error TS2322: Types of property 'forEach' are incompatible. |
| 103 | +!!! error TS2322: Type '(cb: (item: A) => void) => void' is not assignable to type '(cb: (item: A, context: any) => void) => void'. |
| 104 | +!!! error TS2322: Types of parameters 'cb' and 'cb' are incompatible. |
| 105 | + } |
0 commit comments