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
|
=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints2.ts ===
// Generic call with constraints infering type parameter from object member properties
// No errors expected
class Base {
>Base : Symbol(Base, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 0, 0))
x: string;
>x : Symbol(Base.x, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 3, 12))
}
class Derived extends Base {
>Derived : Symbol(Derived, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 5, 1))
>Base : Symbol(Base, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 0, 0))
y: string;
>y : Symbol(Derived.y, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 6, 28))
}
function f<T extends Base>(x: { foo: T; bar: T }) {
>f : Symbol(f, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 8, 1))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 10, 11))
>Base : Symbol(Base, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 0, 0))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 10, 27))
>foo : Symbol(foo, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 10, 31))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 10, 11))
>bar : Symbol(bar, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 10, 39))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 10, 11))
var r: T;
>r : Symbol(r, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 11, 7))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 10, 11))
return r;
>r : Symbol(r, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 11, 7))
}
var r = f({ foo: new Base(), bar: new Derived() });
>r : Symbol(r, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 14, 3))
>f : Symbol(f, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 8, 1))
>foo : Symbol(foo, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 14, 11))
>Base : Symbol(Base, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 0, 0))
>bar : Symbol(bar, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 14, 28))
>Derived : Symbol(Derived, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 5, 1))
var r2 = f({ foo: new Derived(), bar: new Derived() });
>r2 : Symbol(r2, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 15, 3))
>f : Symbol(f, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 8, 1))
>foo : Symbol(foo, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 15, 12))
>Derived : Symbol(Derived, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 5, 1))
>bar : Symbol(bar, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 15, 32))
>Derived : Symbol(Derived, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 5, 1))
interface I<T> {
>I : Symbol(I, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 15, 55))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 18, 12))
a: T;
>a : Symbol(I.a, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 18, 16))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 18, 12))
}
function f2<T extends Base>(x: I<T>) {
>f2 : Symbol(f2, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 20, 1))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 21, 12))
>Base : Symbol(Base, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 0, 0))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 21, 28))
>I : Symbol(I, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 15, 55))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 21, 12))
var r: T;
>r : Symbol(r, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 22, 7))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 21, 12))
return r;
>r : Symbol(r, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 22, 7))
}
var i: I<Derived>;
>i : Symbol(i, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 25, 3))
>I : Symbol(I, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 15, 55))
>Derived : Symbol(Derived, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 5, 1))
var r3 = f2(i);
>r3 : Symbol(r3, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 26, 3))
>f2 : Symbol(f2, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 20, 1))
>i : Symbol(i, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 25, 3))
function f3<T extends Base>(x: T, y: (a: T) => T) {
>f3 : Symbol(f3, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 26, 15))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 29, 12))
>Base : Symbol(Base, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 0, 0))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 29, 28))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 29, 12))
>y : Symbol(y, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 29, 33))
>a : Symbol(a, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 29, 38))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 29, 12))
>T : Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 29, 12))
return y(null);
>y : Symbol(y, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 29, 33))
}
var r4 = f3(new Base(), x => x);
>r4 : Symbol(r4, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 32, 3))
>f3 : Symbol(f3, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 26, 15))
>Base : Symbol(Base, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 0, 0))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 32, 23))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 32, 23))
var r5 = f3(new Derived(), x => x);
>r5 : Symbol(r5, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 33, 3))
>f3 : Symbol(f3, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 26, 15))
>Derived : Symbol(Derived, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 5, 1))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 33, 26))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 33, 26))
var r6 = f3(null, null); // any
>r6 : Symbol(r6, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 35, 3))
>f3 : Symbol(f3, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 26, 15))
var r7 = f3(null, x => x); // any
>r7 : Symbol(r7, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 36, 3))
>f3 : Symbol(f3, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 26, 15))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 36, 17))
>x : Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints2.ts, 36, 17))
|