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
|
=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs2.ts ===
class Base {
>Base : Base
x: string;
>x : string
}
class Derived extends Base {
>Derived : Derived
>Base : Base
y: string;
>y : string
}
class Derived2 extends Base {
>Derived2 : Derived2
>Base : Base
z: string;
>z : string
}
// returns {}[]
function f<T extends Base, U extends Base>(a: { x: T; y: U }) {
>f : <T extends Base, U extends Base>(a: { x: T; y: U; }) => (T | U)[]
>a : { x: T; y: U; }
>x : T
>y : U
return [a.x, a.y];
>[a.x, a.y] : (T | U)[]
>a.x : T
>a : { x: T; y: U; }
>x : T
>a.y : U
>a : { x: T; y: U; }
>y : U
}
var r = f({ x: new Derived(), y: new Derived2() }); // {}[]
>r : (Derived | Derived2)[]
>f({ x: new Derived(), y: new Derived2() }) : (Derived | Derived2)[]
>f : <T extends Base, U extends Base>(a: { x: T; y: U; }) => (T | U)[]
>{ x: new Derived(), y: new Derived2() } : { x: Derived; y: Derived2; }
>x : Derived
>new Derived() : Derived
>Derived : typeof Derived
>y : Derived2
>new Derived2() : Derived2
>Derived2 : typeof Derived2
var r2 = f({ x: new Base(), y: new Derived2() }); // {}[]
>r2 : (Base | Derived2)[]
>f({ x: new Base(), y: new Derived2() }) : (Base | Derived2)[]
>f : <T extends Base, U extends Base>(a: { x: T; y: U; }) => (T | U)[]
>{ x: new Base(), y: new Derived2() } : { x: Base; y: Derived2; }
>x : Base
>new Base() : Base
>Base : typeof Base
>y : Derived2
>new Derived2() : Derived2
>Derived2 : typeof Derived2
function f2<T extends Base, U extends Base>(a: { x: T; y: U }) {
>f2 : <T extends Base, U extends Base>(a: { x: T; y: U; }) => (x: T) => U
>a : { x: T; y: U; }
>x : T
>y : U
return (x: T) => a.y;
>(x: T) => a.y : (x: T) => U
>x : T
>a.y : U
>a : { x: T; y: U; }
>y : U
}
var r3 = f2({ x: new Derived(), y: new Derived2() }); // Derived => Derived2
>r3 : (x: Derived) => Derived2
>f2({ x: new Derived(), y: new Derived2() }) : (x: Derived) => Derived2
>f2 : <T extends Base, U extends Base>(a: { x: T; y: U; }) => (x: T) => U
>{ x: new Derived(), y: new Derived2() } : { x: Derived; y: Derived2; }
>x : Derived
>new Derived() : Derived
>Derived : typeof Derived
>y : Derived2
>new Derived2() : Derived2
>Derived2 : typeof Derived2
interface I<T, U> {
x: T;
>x : T
y: U;
>y : U
}
var i: I<Base, Derived>;
>i : I<Base, Derived>
var r4 = f2(i); // Base => Derived
>r4 : (x: Base) => Derived
>f2(i) : (x: Base) => Derived
>f2 : <T extends Base, U extends Base>(a: { x: T; y: U; }) => (x: T) => U
>i : I<Base, Derived>
|