1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
=== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance5.ts ===
// checking subtype relations for function types as it relates to contextual signature instantiation
// same as subtypingWithCallSignatures2 just with an extra level of indirection in the inheritance chain
class Base { foo: string; }
>Base : Base
>foo : string
class Derived extends Base { bar: string; }
>Derived : Derived
>Base : Base
>bar : string
class Derived2 extends Derived { baz: string; }
>Derived2 : Derived2
>Derived : Derived
>baz : string
class OtherDerived extends Base { bing: string; }
>OtherDerived : OtherDerived
>Base : Base
>bing : string
interface A { // T
// M's
a: (x: number) => number[];
>a : (x: number) => number[]
>x : number
a2: (x: number) => string[];
>a2 : (x: number) => string[]
>x : number
a3: (x: number) => void;
>a3 : (x: number) => void
>x : number
a4: (x: string, y: number) => string;
>a4 : (x: string, y: number) => string
>x : string
>y : number
a5: (x: (arg: string) => number) => string;
>a5 : (x: (arg: string) => number) => string
>x : (arg: string) => number
>arg : string
a6: (x: (arg: Base) => Derived) => Base;
>a6 : (x: (arg: Base) => Derived) => Base
>x : (arg: Base) => Derived
>arg : Base
a7: (x: (arg: Base) => Derived) => (r: Base) => Derived;
>a7 : (x: (arg: Base) => Derived) => (r: Base) => Derived
>x : (arg: Base) => Derived
>arg : Base
>r : Base
a8: (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived;
>a8 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived
>x : (arg: Base) => Derived
>arg : Base
>y : (arg2: Base) => Derived
>arg2 : Base
>r : Base
a9: (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived;
>a9 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived
>x : (arg: Base) => Derived
>arg : Base
>y : (arg2: Base) => Derived
>arg2 : Base
>r : Base
a10: (...x: Derived[]) => Derived;
>a10 : (...x: Derived[]) => Derived
>x : Derived[]
a11: (x: { foo: string }, y: { foo: string; bar: string }) => Base;
>a11 : (x: { foo: string; }, y: { foo: string; bar: string; }) => Base
>x : { foo: string; }
>foo : string
>y : { foo: string; bar: string; }
>foo : string
>bar : string
a12: (x: Array<Base>, y: Array<Derived2>) => Array<Derived>;
>a12 : (x: Base[], y: Derived2[]) => Derived[]
>x : Base[]
>y : Derived2[]
a13: (x: Array<Base>, y: Array<Derived>) => Array<Derived>;
>a13 : (x: Base[], y: Derived[]) => Derived[]
>x : Base[]
>y : Derived[]
a14: (x: { a: string; b: number }) => Object;
>a14 : (x: { a: string; b: number; }) => Object
>x : { a: string; b: number; }
>a : string
>b : number
}
interface B extends A {
a: <T>(x: T) => T[];
>a : <T>(x: T) => T[]
>x : T
}
// S's
interface I extends B {
// N's
a: <T>(x: T) => T[]; // ok, instantiation of N is a subtype of M, T is number
>a : <T>(x: T) => T[]
>x : T
a2: <T>(x: T) => string[]; // ok
>a2 : <T>(x: T) => string[]
>x : T
a3: <T>(x: T) => T; // ok since Base returns void
>a3 : <T>(x: T) => T
>x : T
a4: <T, U>(x: T, y: U) => T; // ok, instantiation of N is a subtype of M, T is string, U is number
>a4 : <T, U>(x: T, y: U) => T
>x : T
>y : U
a5: <T, U>(x: (arg: T) => U) => T; // ok, U is in a parameter position so inferences can be made
>a5 : <T, U>(x: (arg: T) => U) => T
>x : (arg: T) => U
>arg : T
a6: <T extends Base, U extends Derived>(x: (arg: T) => U) => T; // ok, same as a5 but with object type hierarchy
>a6 : <T extends Base, U extends Derived>(x: (arg: T) => U) => T
>x : (arg: T) => U
>arg : T
a7: <T extends Base, U extends Derived>(x: (arg: T) => U) => (r: T) => U; // ok
>a7 : <T extends Base, U extends Derived>(x: (arg: T) => U) => (r: T) => U
>x : (arg: T) => U
>arg : T
>r : T
a8: <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U; // ok
>a8 : <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U
>x : (arg: T) => U
>arg : T
>y : (arg2: T) => U
>arg2 : T
>r : T
a9: <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: string; bing: number }) => U) => (r: T) => U; // ok, same as a8 with compatible object literal
>a9 : <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U
>x : (arg: T) => U
>arg : T
>y : (arg2: { foo: string; bing: number; }) => U
>arg2 : { foo: string; bing: number; }
>foo : string
>bing : number
>r : T
a10: <T extends Derived>(...x: T[]) => T; // ok
>a10 : <T extends Derived>(...x: T[]) => T
>x : T[]
a11: <T extends Base>(x: T, y: T) => T; // ok
>a11 : <T extends Base>(x: T, y: T) => T
>x : T
>y : T
a12: <T extends Array<Base>>(x: Array<Base>, y: T) => Array<Derived>; // ok, less specific parameter type
>a12 : <T extends Base[]>(x: Base[], y: T) => Derived[]
>x : Base[]
>y : T
a13: <T extends Array<Derived>>(x: Array<Base>, y: T) => T; // ok, T = Array<Derived>, satisfies constraint, contextual signature instantiation succeeds
>a13 : <T extends Derived[]>(x: Base[], y: T) => T
>x : Base[]
>y : T
a14: <T, U>(x: { a: T; b: U }) => T; // ok
>a14 : <T, U>(x: { a: T; b: U; }) => T
>x : { a: T; b: U; }
>a : T
>b : U
}
|