2014-08-15 23:33:16 +02:00
|
|
|
=== tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithObjectTypeArgsAndConstraints.ts ===
|
|
|
|
// Generic call with constraints infering type parameter from object member properties
|
|
|
|
// No errors expected
|
|
|
|
|
|
|
|
class C {
|
|
|
|
>C : C
|
|
|
|
|
|
|
|
x: string;
|
|
|
|
>x : string
|
|
|
|
}
|
|
|
|
|
|
|
|
class D {
|
|
|
|
>D : D
|
|
|
|
|
|
|
|
x: string;
|
|
|
|
>x : string
|
|
|
|
|
|
|
|
y: string;
|
|
|
|
>y : string
|
|
|
|
}
|
|
|
|
|
|
|
|
class X<T> {
|
|
|
|
>X : X<T>
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
x: T;
|
|
|
|
>x : T
|
|
|
|
>T : T
|
|
|
|
}
|
|
|
|
|
|
|
|
module Class {
|
|
|
|
>Class : typeof Class
|
|
|
|
|
|
|
|
class G<T extends { x: string }> {
|
|
|
|
>G : G<T>
|
|
|
|
>T : T
|
|
|
|
>x : string
|
|
|
|
|
|
|
|
foo<T extends { x: string }>(t: X<T>, t2: X<T>) {
|
|
|
|
>foo : <T extends { x: string; }>(t: X<T>, t2: X<T>) => T
|
|
|
|
>T : T
|
|
|
|
>x : string
|
|
|
|
>t : X<T>
|
2014-08-19 04:56:03 +02:00
|
|
|
>X : X<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
>T : T
|
|
|
|
>t2 : X<T>
|
2014-08-19 04:56:03 +02:00
|
|
|
>X : X<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
>T : T
|
|
|
|
|
|
|
|
var x: T;
|
|
|
|
>x : T
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
return x;
|
|
|
|
>x : T
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var c1 = new X<C>();
|
|
|
|
>c1 : X<C>
|
|
|
|
>new X<C>() : X<C>
|
|
|
|
>X : typeof X
|
|
|
|
>C : C
|
|
|
|
|
|
|
|
var d1 = new X<D>();
|
|
|
|
>d1 : X<D>
|
|
|
|
>new X<D>() : X<D>
|
|
|
|
>X : typeof X
|
|
|
|
>D : D
|
|
|
|
|
|
|
|
var g: G<{ x: string; y: string }>;
|
|
|
|
>g : G<{ x: string; y: string; }>
|
2014-08-19 04:56:03 +02:00
|
|
|
>G : G<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
>x : string
|
|
|
|
>y : string
|
|
|
|
|
|
|
|
var r = g.foo(c1, d1);
|
|
|
|
>r : C
|
|
|
|
>g.foo(c1, d1) : C
|
|
|
|
>g.foo : <T extends { x: string; }>(t: X<T>, t2: X<T>) => T
|
|
|
|
>g : G<{ x: string; y: string; }>
|
|
|
|
>foo : <T extends { x: string; }>(t: X<T>, t2: X<T>) => T
|
|
|
|
>c1 : X<C>
|
|
|
|
>d1 : X<D>
|
|
|
|
|
|
|
|
var r2 = g.foo(c1, c1);
|
|
|
|
>r2 : C
|
|
|
|
>g.foo(c1, c1) : C
|
|
|
|
>g.foo : <T extends { x: string; }>(t: X<T>, t2: X<T>) => T
|
|
|
|
>g : G<{ x: string; y: string; }>
|
|
|
|
>foo : <T extends { x: string; }>(t: X<T>, t2: X<T>) => T
|
|
|
|
>c1 : X<C>
|
|
|
|
>c1 : X<C>
|
|
|
|
|
|
|
|
class G2<T extends C> {
|
|
|
|
>G2 : G2<T>
|
|
|
|
>T : T
|
|
|
|
>C : C
|
|
|
|
|
|
|
|
foo2<T extends C>(t: X<T>, t2: X<T>) {
|
|
|
|
>foo2 : <T extends C>(t: X<T>, t2: X<T>) => T
|
|
|
|
>T : T
|
|
|
|
>C : C
|
|
|
|
>t : X<T>
|
2014-08-19 04:56:03 +02:00
|
|
|
>X : X<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
>T : T
|
|
|
|
>t2 : X<T>
|
2014-08-19 04:56:03 +02:00
|
|
|
>X : X<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
>T : T
|
|
|
|
|
|
|
|
var x: T;
|
|
|
|
>x : T
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
return x;
|
|
|
|
>x : T
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var g2: G2<D>;
|
|
|
|
>g2 : G2<D>
|
2014-08-19 04:56:03 +02:00
|
|
|
>G2 : G2<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
>D : D
|
|
|
|
|
|
|
|
var r = g2.foo2(c1, d1);
|
|
|
|
>r : C
|
|
|
|
>g2.foo2(c1, d1) : C
|
|
|
|
>g2.foo2 : <T extends C>(t: X<T>, t2: X<T>) => T
|
|
|
|
>g2 : G2<D>
|
|
|
|
>foo2 : <T extends C>(t: X<T>, t2: X<T>) => T
|
|
|
|
>c1 : X<C>
|
|
|
|
>d1 : X<D>
|
|
|
|
|
|
|
|
var r2 = g2.foo2(c1, c1);
|
|
|
|
>r2 : C
|
|
|
|
>g2.foo2(c1, c1) : C
|
|
|
|
>g2.foo2 : <T extends C>(t: X<T>, t2: X<T>) => T
|
|
|
|
>g2 : G2<D>
|
|
|
|
>foo2 : <T extends C>(t: X<T>, t2: X<T>) => T
|
|
|
|
>c1 : X<C>
|
|
|
|
>c1 : X<C>
|
|
|
|
}
|
|
|
|
|
|
|
|
module Interface {
|
|
|
|
>Interface : typeof Interface
|
|
|
|
|
|
|
|
interface G<T extends { x: string }> {
|
|
|
|
>G : G<T>
|
|
|
|
>T : T
|
|
|
|
>x : string
|
|
|
|
|
|
|
|
foo<T extends { x: string }>(t: X<T>, t2: X<T>): T;
|
|
|
|
>foo : <T extends { x: string; }>(t: X<T>, t2: X<T>) => T
|
|
|
|
>T : T
|
|
|
|
>x : string
|
|
|
|
>t : X<T>
|
2014-08-19 04:56:03 +02:00
|
|
|
>X : X<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
>T : T
|
|
|
|
>t2 : X<T>
|
2014-08-19 04:56:03 +02:00
|
|
|
>X : X<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
>T : T
|
|
|
|
>T : T
|
|
|
|
}
|
|
|
|
|
|
|
|
var c1 = new X<C>();
|
|
|
|
>c1 : X<C>
|
|
|
|
>new X<C>() : X<C>
|
|
|
|
>X : typeof X
|
|
|
|
>C : C
|
|
|
|
|
|
|
|
var d1 = new X<D>();
|
|
|
|
>d1 : X<D>
|
|
|
|
>new X<D>() : X<D>
|
|
|
|
>X : typeof X
|
|
|
|
>D : D
|
|
|
|
|
|
|
|
var g: G<{ x: string; y: string }>;
|
|
|
|
>g : G<{ x: string; y: string; }>
|
2014-08-19 04:56:03 +02:00
|
|
|
>G : G<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
>x : string
|
|
|
|
>y : string
|
|
|
|
|
|
|
|
var r = g.foo(c1, d1);
|
|
|
|
>r : C
|
|
|
|
>g.foo(c1, d1) : C
|
|
|
|
>g.foo : <T extends { x: string; }>(t: X<T>, t2: X<T>) => T
|
|
|
|
>g : G<{ x: string; y: string; }>
|
|
|
|
>foo : <T extends { x: string; }>(t: X<T>, t2: X<T>) => T
|
|
|
|
>c1 : X<C>
|
|
|
|
>d1 : X<D>
|
|
|
|
|
|
|
|
var r2 = g.foo(c1, c1);
|
|
|
|
>r2 : C
|
|
|
|
>g.foo(c1, c1) : C
|
|
|
|
>g.foo : <T extends { x: string; }>(t: X<T>, t2: X<T>) => T
|
|
|
|
>g : G<{ x: string; y: string; }>
|
|
|
|
>foo : <T extends { x: string; }>(t: X<T>, t2: X<T>) => T
|
|
|
|
>c1 : X<C>
|
|
|
|
>c1 : X<C>
|
|
|
|
|
|
|
|
interface G2<T extends C> {
|
|
|
|
>G2 : G2<T>
|
|
|
|
>T : T
|
|
|
|
>C : C
|
|
|
|
|
|
|
|
foo2<T extends C>(t: X<T>, t2: X<T>): T;
|
|
|
|
>foo2 : <T extends C>(t: X<T>, t2: X<T>) => T
|
|
|
|
>T : T
|
|
|
|
>C : C
|
|
|
|
>t : X<T>
|
2014-08-19 04:56:03 +02:00
|
|
|
>X : X<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
>T : T
|
|
|
|
>t2 : X<T>
|
2014-08-19 04:56:03 +02:00
|
|
|
>X : X<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
>T : T
|
|
|
|
>T : T
|
|
|
|
}
|
|
|
|
|
|
|
|
var g2: G2<D>;
|
|
|
|
>g2 : G2<D>
|
2014-08-19 04:56:03 +02:00
|
|
|
>G2 : G2<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
>D : D
|
|
|
|
|
|
|
|
var r = g2.foo2(c1, d1);
|
|
|
|
>r : C
|
|
|
|
>g2.foo2(c1, d1) : C
|
|
|
|
>g2.foo2 : <T extends C>(t: X<T>, t2: X<T>) => T
|
|
|
|
>g2 : G2<D>
|
|
|
|
>foo2 : <T extends C>(t: X<T>, t2: X<T>) => T
|
|
|
|
>c1 : X<C>
|
|
|
|
>d1 : X<D>
|
|
|
|
|
|
|
|
var r2 = g2.foo2(c1, c1);
|
|
|
|
>r2 : C
|
|
|
|
>g2.foo2(c1, c1) : C
|
|
|
|
>g2.foo2 : <T extends C>(t: X<T>, t2: X<T>) => T
|
|
|
|
>g2 : G2<D>
|
|
|
|
>foo2 : <T extends C>(t: X<T>, t2: X<T>) => T
|
|
|
|
>c1 : X<C>
|
|
|
|
>c1 : X<C>
|
|
|
|
}
|