TypeScript/tests/baselines/reference/genericCallWithObjectTypeArgsAndConstraints.types

109 lines
5.7 KiB
Plaintext
Raw Normal View History

2014-08-15 23:33:16 +02:00
=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints.ts ===
// Generic call with constraints infering type parameter from object member properties
// No errors expected
class C {
2015-04-13 23:01:57 +02:00
>C : C, Symbol(C, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 0, 0))
2014-08-15 23:33:16 +02:00
x: string;
2015-04-13 23:01:57 +02:00
>x : string, Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 3, 9))
2014-08-15 23:33:16 +02:00
}
class D {
2015-04-13 23:01:57 +02:00
>D : D, Symbol(D, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 5, 1))
2014-08-15 23:33:16 +02:00
x: string;
2015-04-13 23:01:57 +02:00
>x : string, Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 7, 9))
2014-08-15 23:33:16 +02:00
y: string;
2015-04-13 23:01:57 +02:00
>y : string, Symbol(y, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 8, 14))
2014-08-15 23:33:16 +02:00
}
class X<T> {
2015-04-13 23:01:57 +02:00
>X : X<T>, Symbol(X, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 10, 1))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 12, 8))
2014-08-15 23:33:16 +02:00
x: T;
2015-04-13 23:01:57 +02:00
>x : T, Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 12, 12))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 12, 8))
2014-08-15 23:33:16 +02:00
}
function foo<T extends { x: string }>(t: X<T>, t2: X<T>) {
2015-04-13 23:01:57 +02:00
>foo : <T extends { x: string; }>(t: X<T>, t2: X<T>) => T, Symbol(foo, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 14, 1))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 16, 13))
>x : string, Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 16, 24))
>t : X<T>, Symbol(t, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 16, 38))
>X : X<T>, Symbol(X, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 10, 1))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 16, 13))
>t2 : X<T>, Symbol(t2, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 16, 46))
>X : X<T>, Symbol(X, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 10, 1))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 16, 13))
2014-08-15 23:33:16 +02:00
var x: T;
2015-04-13 23:01:57 +02:00
>x : T, Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 17, 7))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 16, 13))
2014-08-15 23:33:16 +02:00
return x;
2015-04-13 23:01:57 +02:00
>x : T, Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 17, 7))
2014-08-15 23:33:16 +02:00
}
var c1 = new X<C>();
2015-04-13 23:01:57 +02:00
>c1 : X<C>, Symbol(c1, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 21, 3))
2014-08-15 23:33:16 +02:00
>new X<C>() : X<C>
2015-04-13 23:01:57 +02:00
>X : typeof X, Symbol(X, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 10, 1))
>C : C, Symbol(C, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 0, 0))
2014-08-15 23:33:16 +02:00
var d1 = new X<D>();
2015-04-13 23:01:57 +02:00
>d1 : X<D>, Symbol(d1, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 22, 3))
2014-08-15 23:33:16 +02:00
>new X<D>() : X<D>
2015-04-13 23:01:57 +02:00
>X : typeof X, Symbol(X, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 10, 1))
>D : D, Symbol(D, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 5, 1))
2014-08-15 23:33:16 +02:00
var r = foo(c1, d1);
2015-04-13 23:01:57 +02:00
>r : C, Symbol(r, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 23, 3), Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 31, 3))
2014-08-15 23:33:16 +02:00
>foo(c1, d1) : C
2015-04-13 23:01:57 +02:00
>foo : <T extends { x: string; }>(t: X<T>, t2: X<T>) => T, Symbol(foo, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 14, 1))
>c1 : X<C>, Symbol(c1, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 21, 3))
>d1 : X<D>, Symbol(d1, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 22, 3))
2014-08-15 23:33:16 +02:00
var r2 = foo(c1, c1);
2015-04-13 23:01:57 +02:00
>r2 : C, Symbol(r2, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 24, 3), Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 32, 3))
2014-08-15 23:33:16 +02:00
>foo(c1, c1) : C
2015-04-13 23:01:57 +02:00
>foo : <T extends { x: string; }>(t: X<T>, t2: X<T>) => T, Symbol(foo, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 14, 1))
>c1 : X<C>, Symbol(c1, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 21, 3))
>c1 : X<C>, Symbol(c1, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 21, 3))
2014-08-15 23:33:16 +02:00
function foo2<T extends C>(t: X<T>, t2: X<T>) {
2015-04-13 23:01:57 +02:00
>foo2 : <T extends C>(t: X<T>, t2: X<T>) => T, Symbol(foo2, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 24, 21))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 26, 14))
>C : C, Symbol(C, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 0, 0))
>t : X<T>, Symbol(t, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 26, 27))
>X : X<T>, Symbol(X, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 10, 1))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 26, 14))
>t2 : X<T>, Symbol(t2, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 26, 35))
>X : X<T>, Symbol(X, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 10, 1))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 26, 14))
2014-08-15 23:33:16 +02:00
var x: T;
2015-04-13 23:01:57 +02:00
>x : T, Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 27, 7))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 26, 14))
2014-08-15 23:33:16 +02:00
return x;
2015-04-13 23:01:57 +02:00
>x : T, Symbol(x, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 27, 7))
2014-08-15 23:33:16 +02:00
}
var r = foo2(c1, d1);
2015-04-13 23:01:57 +02:00
>r : C, Symbol(r, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 23, 3), Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 31, 3))
2014-08-15 23:33:16 +02:00
>foo2(c1, d1) : C
2015-04-13 23:01:57 +02:00
>foo2 : <T extends C>(t: X<T>, t2: X<T>) => T, Symbol(foo2, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 24, 21))
>c1 : X<C>, Symbol(c1, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 21, 3))
>d1 : X<D>, Symbol(d1, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 22, 3))
2014-08-15 23:33:16 +02:00
var r2 = foo2(c1, c1);
2015-04-13 23:01:57 +02:00
>r2 : C, Symbol(r2, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 24, 3), Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 32, 3))
2014-08-15 23:33:16 +02:00
>foo2(c1, c1) : C
2015-04-13 23:01:57 +02:00
>foo2 : <T extends C>(t: X<T>, t2: X<T>) => T, Symbol(foo2, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 24, 21))
>c1 : X<C>, Symbol(c1, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 21, 3))
>c1 : X<C>, Symbol(c1, Decl(genericCallWithObjectTypeArgsAndConstraints.ts, 21, 3))
2014-08-15 23:33:16 +02:00