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
|
=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts ===
// Generic call with constraints infering type parameter from object member properties
class Base {
>Base : Symbol(Base, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 0, 0))
x: string;
>x : Symbol(Base.x, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 2, 12))
}
class Derived extends Base {
>Derived : Symbol(Derived, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 4, 1))
>Base : Symbol(Base, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 0, 0))
y: string;
>y : Symbol(Derived.y, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 5, 28))
}
class Derived2 extends Base {
>Derived2 : Symbol(Derived2, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 7, 1))
>Base : Symbol(Base, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 0, 0))
z: string;
>z : Symbol(Derived2.z, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 8, 29))
}
function f<T extends Base>(a: { x: T; y: T }) {
>f : Symbol(f, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 10, 1))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 12, 11))
>Base : Symbol(Base, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 0, 0))
>a : Symbol(a, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 12, 27))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 12, 31))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 12, 11))
>y : Symbol(y, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 12, 37))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 12, 11))
var r: T;
>r : Symbol(r, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 13, 7))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 12, 11))
return r;
>r : Symbol(r, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 13, 7))
}
var r1 = f({ x: new Derived(), y: new Derived2() }); // error because neither is supertype of the other
>r1 : Symbol(r1, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 17, 3))
>f : Symbol(f, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 10, 1))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 17, 12))
>Derived : Symbol(Derived, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 4, 1))
>y : Symbol(y, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 17, 30))
>Derived2 : Symbol(Derived2, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 7, 1))
function f2<T extends Base, U extends { x: T; y: T }>(a: U) {
>f2 : Symbol(f2, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 17, 52))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 19, 12))
>Base : Symbol(Base, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 0, 0))
>U : Symbol(U, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 19, 27))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 19, 39))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 19, 12))
>y : Symbol(y, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 19, 45))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 19, 12))
>a : Symbol(a, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 19, 54))
>U : Symbol(U, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 19, 27))
var r: T;
>r : Symbol(r, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 20, 7))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 19, 12))
return r;
>r : Symbol(r, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 20, 7))
}
var r2 = f2({ x: new Derived(), y: new Derived2() }); // ok
>r2 : Symbol(r2, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 24, 3))
>f2 : Symbol(f2, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 17, 52))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 24, 13))
>Derived : Symbol(Derived, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 4, 1))
>y : Symbol(y, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 24, 31))
>Derived2 : Symbol(Derived2, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 7, 1))
var r3 = f2({ x: new Derived(), y: new Derived2() }); // ok
>r3 : Symbol(r3, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 25, 3))
>f2 : Symbol(f2, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 17, 52))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 25, 13))
>Derived : Symbol(Derived, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 4, 1))
>y : Symbol(y, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 25, 31))
>Derived2 : Symbol(Derived2, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 7, 1))
function f3<T extends Base>(y: (a: T) => T, x: T) {
>f3 : Symbol(f3, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 25, 53))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 28, 12))
>Base : Symbol(Base, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 0, 0))
>y : Symbol(y, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 28, 28))
>a : Symbol(a, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 28, 32))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 28, 12))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 28, 12))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 28, 43))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 28, 12))
return y(null);
>y : Symbol(y, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 28, 28))
}
// all ok - second argument is processed before x is fixed
var r4 = f3(x => x, new Base());
>r4 : Symbol(r4, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 33, 3))
>f3 : Symbol(f3, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 25, 53))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 33, 12))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 33, 12))
>Base : Symbol(Base, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 0, 0))
var r5 = f3(x => x, new Derived());
>r5 : Symbol(r5, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 34, 3))
>f3 : Symbol(f3, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 25, 53))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 34, 12))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 34, 12))
>Derived : Symbol(Derived, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 4, 1))
var r6 = f3(x => x, null);
>r6 : Symbol(r6, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 35, 3))
>f3 : Symbol(f3, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 25, 53))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 35, 12))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints3.ts, 35, 12))
|