2014-08-15 23:33:16 +02:00
|
|
|
=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithConstraintsTypeArgumentInference.ts ===
|
|
|
|
// Basic type inference with generic calls and constraints, no errors expected
|
|
|
|
|
|
|
|
class Base { foo: string; }
|
|
|
|
>Base : Base
|
|
|
|
>foo : string
|
|
|
|
|
|
|
|
class Derived extends Base { bar: string; }
|
|
|
|
>Derived : Derived
|
|
|
|
>Base : Base
|
|
|
|
>bar : string
|
|
|
|
|
|
|
|
class Derived2 extends Derived { baz: string; }
|
|
|
|
>Derived2 : Derived2
|
|
|
|
>Derived : Derived
|
|
|
|
>baz : string
|
|
|
|
|
|
|
|
var b: Base;
|
|
|
|
>b : Base
|
|
|
|
>Base : Base
|
|
|
|
|
|
|
|
var d1: Derived;
|
|
|
|
>d1 : Derived
|
|
|
|
>Derived : Derived
|
|
|
|
|
|
|
|
var d2: Derived2;
|
|
|
|
>d2 : Derived2
|
|
|
|
>Derived2 : Derived2
|
|
|
|
|
|
|
|
function foo<T extends Base>(t: T) {
|
|
|
|
>foo : <T extends Base>(t: T) => T
|
|
|
|
>T : T
|
|
|
|
>Base : Base
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
return t;
|
|
|
|
>t : T
|
|
|
|
}
|
|
|
|
|
|
|
|
var r = foo(b); // Base
|
|
|
|
>r : Base
|
|
|
|
>foo(b) : Base
|
|
|
|
>foo : <T extends Base>(t: T) => T
|
|
|
|
>b : Base
|
|
|
|
|
|
|
|
var r2 = foo(d1); // Derived
|
|
|
|
>r2 : Derived
|
|
|
|
>foo(d1) : Derived
|
|
|
|
>foo : <T extends Base>(t: T) => T
|
|
|
|
>d1 : Derived
|
|
|
|
|
|
|
|
function foo2<T extends Base, U extends Derived>(t: T, u: U) {
|
|
|
|
>foo2 : <T extends Base, U extends Derived>(t: T, u: U) => U
|
|
|
|
>T : T
|
|
|
|
>Base : Base
|
|
|
|
>U : U
|
|
|
|
>Derived : Derived
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
return u;
|
|
|
|
>u : U
|
|
|
|
}
|
|
|
|
|
|
|
|
function foo2b<T extends Base, U extends Derived>(u: U) {
|
|
|
|
>foo2b : <T extends Base, U extends Derived>(u: U) => T
|
|
|
|
>T : T
|
|
|
|
>Base : Base
|
|
|
|
>U : U
|
|
|
|
>Derived : Derived
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
var x: T;
|
|
|
|
>x : T
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
return x;
|
|
|
|
>x : T
|
|
|
|
}
|
|
|
|
|
|
|
|
function foo2c<T extends Base, U extends Derived>() {
|
|
|
|
>foo2c : <T extends Base, U extends Derived>() => T
|
|
|
|
>T : T
|
|
|
|
>Base : Base
|
|
|
|
>U : U
|
|
|
|
>Derived : Derived
|
|
|
|
|
|
|
|
var x: T;
|
|
|
|
>x : T
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
return x;
|
|
|
|
>x : T
|
|
|
|
}
|
|
|
|
|
|
|
|
var r3 = foo2b(d1); // Base
|
|
|
|
>r3 : Base
|
|
|
|
>foo2b(d1) : Base
|
|
|
|
>foo2b : <T extends Base, U extends Derived>(u: U) => T
|
|
|
|
>d1 : Derived
|
|
|
|
|
|
|
|
var r3b = foo2c(); // Base
|
|
|
|
>r3b : Base
|
|
|
|
>foo2c() : Base
|
|
|
|
>foo2c : <T extends Base, U extends Derived>() => T
|
|
|
|
|
|
|
|
class C<T extends Base, U extends Derived> {
|
|
|
|
>C : C<T, U>
|
|
|
|
>T : T
|
|
|
|
>Base : Base
|
|
|
|
>U : U
|
|
|
|
>Derived : Derived
|
|
|
|
|
|
|
|
constructor(public t: T, public u: U) {
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
}
|
|
|
|
|
|
|
|
foo(t: T, u: U) {
|
|
|
|
>foo : (t: T, u: U) => T
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
return t;
|
|
|
|
>t : T
|
|
|
|
}
|
|
|
|
|
|
|
|
foo2(t: T, u: U) {
|
|
|
|
>foo2 : (t: T, u: U) => U
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
return u;
|
|
|
|
>u : U
|
|
|
|
}
|
|
|
|
|
|
|
|
foo3<T extends Derived>(t: T, u: U) {
|
|
|
|
>foo3 : <T extends Derived>(t: T, u: U) => T
|
|
|
|
>T : T
|
|
|
|
>Derived : Derived
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
return t;
|
|
|
|
>t : T
|
|
|
|
}
|
|
|
|
|
|
|
|
foo4<U extends Derived2>(t: T, u: U) {
|
|
|
|
>foo4 : <U extends Derived2>(t: T, u: U) => T
|
|
|
|
>U : U
|
|
|
|
>Derived2 : Derived2
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
return t;
|
|
|
|
>t : T
|
|
|
|
}
|
|
|
|
|
|
|
|
foo5<T extends Derived, U extends Derived2>(t: T, u: U) {
|
|
|
|
>foo5 : <T extends Derived, U extends Derived2>(t: T, u: U) => T
|
|
|
|
>T : T
|
|
|
|
>Derived : Derived
|
|
|
|
>U : U
|
|
|
|
>Derived2 : Derived2
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
return t;
|
|
|
|
>t : T
|
|
|
|
}
|
|
|
|
|
|
|
|
foo6<T extends Derived, U extends Derived2>() {
|
|
|
|
>foo6 : <T extends Derived, U extends Derived2>() => T
|
|
|
|
>T : T
|
|
|
|
>Derived : Derived
|
|
|
|
>U : U
|
|
|
|
>Derived2 : Derived2
|
|
|
|
|
|
|
|
var x: T;
|
|
|
|
>x : T
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
return x;
|
|
|
|
>x : T
|
|
|
|
}
|
|
|
|
|
|
|
|
foo7<T extends Base, U extends Derived>(u: U) {
|
|
|
|
>foo7 : <T extends Base, U extends Derived>(u: U) => T
|
|
|
|
>T : T
|
|
|
|
>Base : Base
|
|
|
|
>U : U
|
|
|
|
>Derived : Derived
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
var x: T;
|
|
|
|
>x : T
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
return x;
|
|
|
|
>x : T
|
|
|
|
}
|
|
|
|
|
|
|
|
foo8<T extends Base, U extends Derived>() {
|
|
|
|
>foo8 : <T extends Base, U extends Derived>() => T
|
|
|
|
>T : T
|
|
|
|
>Base : Base
|
|
|
|
>U : U
|
|
|
|
>Derived : Derived
|
|
|
|
|
|
|
|
var x: T;
|
|
|
|
>x : T
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
return x;
|
|
|
|
>x : T
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var c = new C(b, d1);
|
|
|
|
>c : C<Base, Derived>
|
|
|
|
>new C(b, d1) : C<Base, Derived>
|
|
|
|
>C : typeof C
|
|
|
|
>b : Base
|
|
|
|
>d1 : Derived
|
|
|
|
|
|
|
|
var r4 = c.foo(d1, d2); // Base
|
|
|
|
>r4 : Base
|
|
|
|
>c.foo(d1, d2) : Base
|
|
|
|
>c.foo : (t: Base, u: Derived) => Base
|
|
|
|
>c : C<Base, Derived>
|
|
|
|
>foo : (t: Base, u: Derived) => Base
|
|
|
|
>d1 : Derived
|
|
|
|
>d2 : Derived2
|
|
|
|
|
|
|
|
var r5 = c.foo2(b, d2); // Derived
|
|
|
|
>r5 : Derived
|
|
|
|
>c.foo2(b, d2) : Derived
|
|
|
|
>c.foo2 : (t: Base, u: Derived) => Derived
|
|
|
|
>c : C<Base, Derived>
|
|
|
|
>foo2 : (t: Base, u: Derived) => Derived
|
|
|
|
>b : Base
|
|
|
|
>d2 : Derived2
|
|
|
|
|
|
|
|
var r6 = c.foo3(d1, d1); // Derived
|
|
|
|
>r6 : Derived
|
|
|
|
>c.foo3(d1, d1) : Derived
|
|
|
|
>c.foo3 : <T extends Derived>(t: T, u: Derived) => T
|
|
|
|
>c : C<Base, Derived>
|
|
|
|
>foo3 : <T extends Derived>(t: T, u: Derived) => T
|
|
|
|
>d1 : Derived
|
|
|
|
>d1 : Derived
|
|
|
|
|
|
|
|
var r7 = c.foo4(d1, d2); // Base
|
|
|
|
>r7 : Base
|
|
|
|
>c.foo4(d1, d2) : Base
|
|
|
|
>c.foo4 : <U extends Derived2>(t: Base, u: U) => Base
|
|
|
|
>c : C<Base, Derived>
|
|
|
|
>foo4 : <U extends Derived2>(t: Base, u: U) => Base
|
|
|
|
>d1 : Derived
|
|
|
|
>d2 : Derived2
|
|
|
|
|
|
|
|
var r8 = c.foo5(d1, d2); // Derived
|
|
|
|
>r8 : Derived
|
|
|
|
>c.foo5(d1, d2) : Derived
|
|
|
|
>c.foo5 : <T extends Derived, U extends Derived2>(t: T, u: U) => T
|
|
|
|
>c : C<Base, Derived>
|
|
|
|
>foo5 : <T extends Derived, U extends Derived2>(t: T, u: U) => T
|
|
|
|
>d1 : Derived
|
|
|
|
>d2 : Derived2
|
|
|
|
|
|
|
|
var r8b = c.foo5(d2, d2); // Derived2
|
|
|
|
>r8b : Derived2
|
|
|
|
>c.foo5(d2, d2) : Derived2
|
|
|
|
>c.foo5 : <T extends Derived, U extends Derived2>(t: T, u: U) => T
|
|
|
|
>c : C<Base, Derived>
|
|
|
|
>foo5 : <T extends Derived, U extends Derived2>(t: T, u: U) => T
|
|
|
|
>d2 : Derived2
|
|
|
|
>d2 : Derived2
|
|
|
|
|
|
|
|
var r9 = c.foo6(); // Derived
|
|
|
|
>r9 : Derived
|
|
|
|
>c.foo6() : Derived
|
|
|
|
>c.foo6 : <T extends Derived, U extends Derived2>() => T
|
|
|
|
>c : C<Base, Derived>
|
|
|
|
>foo6 : <T extends Derived, U extends Derived2>() => T
|
|
|
|
|
|
|
|
var r10 = c.foo7(d1); // Base
|
|
|
|
>r10 : Base
|
|
|
|
>c.foo7(d1) : Base
|
|
|
|
>c.foo7 : <T extends Base, U extends Derived>(u: U) => T
|
|
|
|
>c : C<Base, Derived>
|
|
|
|
>foo7 : <T extends Base, U extends Derived>(u: U) => T
|
|
|
|
>d1 : Derived
|
|
|
|
|
|
|
|
var r11 = c.foo8(); // Base
|
|
|
|
>r11 : Base
|
|
|
|
>c.foo8() : Base
|
|
|
|
>c.foo8 : <T extends Base, U extends Derived>() => T
|
|
|
|
>c : C<Base, Derived>
|
|
|
|
>foo8 : <T extends Base, U extends Derived>() => T
|
|
|
|
|
|
|
|
interface I<T extends Base, U extends Derived> {
|
|
|
|
>I : I<T, U>
|
|
|
|
>T : T
|
|
|
|
>Base : Base
|
|
|
|
>U : U
|
|
|
|
>Derived : Derived
|
|
|
|
|
|
|
|
new (t: T, u: U);
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
foo(t: T, u: U): T;
|
|
|
|
>foo : (t: T, u: U) => T
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
foo2(t: T, u: U): U;
|
|
|
|
>foo2 : (t: T, u: U) => U
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
foo3<T extends Derived>(t: T, u: U): T;
|
|
|
|
>foo3 : <T extends Derived>(t: T, u: U) => T
|
|
|
|
>T : T
|
|
|
|
>Derived : Derived
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
foo4<U extends Derived2>(t: T, u: U): T;
|
|
|
|
>foo4 : <U extends Derived2>(t: T, u: U) => T
|
|
|
|
>U : U
|
|
|
|
>Derived2 : Derived2
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
foo5<T extends Derived, U extends Derived2>(t: T, u: U): T;
|
|
|
|
>foo5 : <T extends Derived, U extends Derived2>(t: T, u: U) => T
|
|
|
|
>T : T
|
|
|
|
>Derived : Derived
|
|
|
|
>U : U
|
|
|
|
>Derived2 : Derived2
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
foo6<T extends Derived, U extends Derived2>(): T;
|
|
|
|
>foo6 : <T extends Derived, U extends Derived2>() => T
|
|
|
|
>T : T
|
|
|
|
>Derived : Derived
|
|
|
|
>U : U
|
|
|
|
>Derived2 : Derived2
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
foo7<T extends Base, U extends Derived>(u: U): T;
|
|
|
|
>foo7 : <T extends Base, U extends Derived>(u: U) => T
|
|
|
|
>T : T
|
|
|
|
>Base : Base
|
|
|
|
>U : U
|
|
|
|
>Derived : Derived
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
foo8<T extends Base, U extends Derived>(): T;
|
|
|
|
>foo8 : <T extends Base, U extends Derived>() => T
|
|
|
|
>T : T
|
|
|
|
>Base : Base
|
|
|
|
>U : U
|
|
|
|
>Derived : Derived
|
|
|
|
>T : T
|
|
|
|
}
|
|
|
|
|
|
|
|
var i: I<Base, Derived>;
|
|
|
|
>i : I<Base, Derived>
|
2014-08-19 04:56:03 +02:00
|
|
|
>I : I<T, U>
|
2014-08-15 23:33:16 +02:00
|
|
|
>Base : Base
|
|
|
|
>Derived : Derived
|
|
|
|
|
|
|
|
var r4 = i.foo(d1, d2); // Base
|
|
|
|
>r4 : Base
|
|
|
|
>i.foo(d1, d2) : Base
|
|
|
|
>i.foo : (t: Base, u: Derived) => Base
|
|
|
|
>i : I<Base, Derived>
|
|
|
|
>foo : (t: Base, u: Derived) => Base
|
|
|
|
>d1 : Derived
|
|
|
|
>d2 : Derived2
|
|
|
|
|
|
|
|
var r5 = i.foo2(b, d2); // Derived
|
|
|
|
>r5 : Derived
|
|
|
|
>i.foo2(b, d2) : Derived
|
|
|
|
>i.foo2 : (t: Base, u: Derived) => Derived
|
|
|
|
>i : I<Base, Derived>
|
|
|
|
>foo2 : (t: Base, u: Derived) => Derived
|
|
|
|
>b : Base
|
|
|
|
>d2 : Derived2
|
|
|
|
|
|
|
|
var r6 = i.foo3(d1, d1); // Derived
|
|
|
|
>r6 : Derived
|
|
|
|
>i.foo3(d1, d1) : Derived
|
|
|
|
>i.foo3 : <T extends Derived>(t: T, u: Derived) => T
|
|
|
|
>i : I<Base, Derived>
|
|
|
|
>foo3 : <T extends Derived>(t: T, u: Derived) => T
|
|
|
|
>d1 : Derived
|
|
|
|
>d1 : Derived
|
|
|
|
|
|
|
|
var r7 = i.foo4(d1, d2); // Base
|
|
|
|
>r7 : Base
|
|
|
|
>i.foo4(d1, d2) : Base
|
|
|
|
>i.foo4 : <U extends Derived2>(t: Base, u: U) => Base
|
|
|
|
>i : I<Base, Derived>
|
|
|
|
>foo4 : <U extends Derived2>(t: Base, u: U) => Base
|
|
|
|
>d1 : Derived
|
|
|
|
>d2 : Derived2
|
|
|
|
|
|
|
|
var r8 = i.foo5(d1, d2); // Derived
|
|
|
|
>r8 : Derived
|
|
|
|
>i.foo5(d1, d2) : Derived
|
|
|
|
>i.foo5 : <T extends Derived, U extends Derived2>(t: T, u: U) => T
|
|
|
|
>i : I<Base, Derived>
|
|
|
|
>foo5 : <T extends Derived, U extends Derived2>(t: T, u: U) => T
|
|
|
|
>d1 : Derived
|
|
|
|
>d2 : Derived2
|
|
|
|
|
|
|
|
var r8b = i.foo5(d2, d2); // Derived2
|
|
|
|
>r8b : Derived2
|
|
|
|
>i.foo5(d2, d2) : Derived2
|
|
|
|
>i.foo5 : <T extends Derived, U extends Derived2>(t: T, u: U) => T
|
|
|
|
>i : I<Base, Derived>
|
|
|
|
>foo5 : <T extends Derived, U extends Derived2>(t: T, u: U) => T
|
|
|
|
>d2 : Derived2
|
|
|
|
>d2 : Derived2
|
|
|
|
|
|
|
|
var r9 = i.foo6(); // Derived
|
|
|
|
>r9 : Derived
|
|
|
|
>i.foo6() : Derived
|
|
|
|
>i.foo6 : <T extends Derived, U extends Derived2>() => T
|
|
|
|
>i : I<Base, Derived>
|
|
|
|
>foo6 : <T extends Derived, U extends Derived2>() => T
|
|
|
|
|
|
|
|
var r10 = i.foo7(d1); // Base
|
|
|
|
>r10 : Base
|
|
|
|
>i.foo7(d1) : Base
|
|
|
|
>i.foo7 : <T extends Base, U extends Derived>(u: U) => T
|
|
|
|
>i : I<Base, Derived>
|
|
|
|
>foo7 : <T extends Base, U extends Derived>(u: U) => T
|
|
|
|
>d1 : Derived
|
|
|
|
|
|
|
|
var r11 = i.foo8(); // Base
|
|
|
|
>r11 : Base
|
|
|
|
>i.foo8() : Base
|
|
|
|
>i.foo8 : <T extends Base, U extends Derived>() => T
|
|
|
|
>i : I<Base, Derived>
|
|
|
|
>foo8 : <T extends Base, U extends Derived>() => T
|
|
|
|
|