124 lines
6.6 KiB
Text
124 lines
6.6 KiB
Text
=== 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(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(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(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))
|
|
|