2014-08-15 23:33:16 +02:00
|
|
|
=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallTypeArgumentInference.ts ===
|
|
|
|
// Basic type inference with generic calls, no errors expected
|
|
|
|
|
|
|
|
function foo<T>(t: T) {
|
|
|
|
>foo : <T>(t: T) => T
|
|
|
|
>T : T
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
return t;
|
|
|
|
>t : T
|
|
|
|
}
|
|
|
|
|
|
|
|
var r = foo(''); // string
|
|
|
|
>r : string
|
|
|
|
>foo('') : string
|
|
|
|
>foo : <T>(t: T) => T
|
|
|
|
|
|
|
|
function foo2<T, U>(t: T, u: U) {
|
|
|
|
>foo2 : <T, U>(t: T, u: U) => U
|
|
|
|
>T : T
|
|
|
|
>U : U
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
return u;
|
|
|
|
>u : U
|
|
|
|
}
|
|
|
|
|
|
|
|
function foo2b<T, U>(u: U) {
|
|
|
|
>foo2b : <T, U>(u: U) => T
|
|
|
|
>T : T
|
|
|
|
>U : U
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
var x: T;
|
|
|
|
>x : T
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
return x;
|
|
|
|
>x : T
|
|
|
|
}
|
|
|
|
|
|
|
|
var r2 = foo2('', 1); // number
|
|
|
|
>r2 : number
|
|
|
|
>foo2('', 1) : number
|
|
|
|
>foo2 : <T, U>(t: T, u: U) => U
|
|
|
|
|
|
|
|
var r3 = foo2b(1); // {}
|
|
|
|
>r3 : {}
|
|
|
|
>foo2b(1) : {}
|
|
|
|
>foo2b : <T, U>(u: U) => T
|
|
|
|
|
|
|
|
class C<T, U> {
|
|
|
|
>C : C<T, U>
|
|
|
|
>T : T
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
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>(t: T, u: U) {
|
|
|
|
>foo3 : <T>(t: T, u: U) => T
|
|
|
|
>T : T
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
return t;
|
|
|
|
>t : T
|
|
|
|
}
|
|
|
|
|
|
|
|
foo4<U>(t: T, u: U) {
|
|
|
|
>foo4 : <U>(t: T, u: U) => T
|
|
|
|
>U : U
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
return t;
|
|
|
|
>t : T
|
|
|
|
}
|
|
|
|
|
|
|
|
foo5<T,U>(t: T, u: U) {
|
|
|
|
>foo5 : <T, U>(t: T, u: U) => T
|
|
|
|
>T : T
|
|
|
|
>U : U
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
return t;
|
|
|
|
>t : T
|
|
|
|
}
|
|
|
|
|
|
|
|
foo6<T, U>() {
|
|
|
|
>foo6 : <T, U>() => T
|
|
|
|
>T : T
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
var x: T;
|
|
|
|
>x : T
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
return x;
|
|
|
|
>x : T
|
|
|
|
}
|
|
|
|
|
|
|
|
foo7<T, U>(u: U) {
|
|
|
|
>foo7 : <T, U>(u: U) => T
|
|
|
|
>T : T
|
|
|
|
>U : U
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
var x: T;
|
|
|
|
>x : T
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
return x;
|
|
|
|
>x : T
|
|
|
|
}
|
|
|
|
|
|
|
|
foo8<T, U>() {
|
|
|
|
>foo8 : <T, U>() => T
|
|
|
|
>T : T
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
var x: T;
|
|
|
|
>x : T
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
return x;
|
|
|
|
>x : T
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var c = new C('', 1);
|
|
|
|
>c : C<string, number>
|
|
|
|
>new C('', 1) : C<string, number>
|
|
|
|
>C : typeof C
|
|
|
|
|
|
|
|
var r4 = c.foo('', 1); // string
|
|
|
|
>r4 : string
|
|
|
|
>c.foo('', 1) : string
|
|
|
|
>c.foo : (t: string, u: number) => string
|
|
|
|
>c : C<string, number>
|
|
|
|
>foo : (t: string, u: number) => string
|
|
|
|
|
|
|
|
var r5 = c.foo2('', 1); // number
|
|
|
|
>r5 : number
|
|
|
|
>c.foo2('', 1) : number
|
|
|
|
>c.foo2 : (t: string, u: number) => number
|
|
|
|
>c : C<string, number>
|
|
|
|
>foo2 : (t: string, u: number) => number
|
|
|
|
|
|
|
|
var r6 = c.foo3(true, 1); // boolean
|
|
|
|
>r6 : boolean
|
|
|
|
>c.foo3(true, 1) : boolean
|
|
|
|
>c.foo3 : <T>(t: T, u: number) => T
|
|
|
|
>c : C<string, number>
|
|
|
|
>foo3 : <T>(t: T, u: number) => T
|
|
|
|
|
|
|
|
var r7 = c.foo4('', true); // string
|
|
|
|
>r7 : string
|
|
|
|
>c.foo4('', true) : string
|
|
|
|
>c.foo4 : <U>(t: string, u: U) => string
|
|
|
|
>c : C<string, number>
|
|
|
|
>foo4 : <U>(t: string, u: U) => string
|
|
|
|
|
|
|
|
var r8 = c.foo5(true, 1); // boolean
|
|
|
|
>r8 : boolean
|
|
|
|
>c.foo5(true, 1) : boolean
|
|
|
|
>c.foo5 : <T, U>(t: T, u: U) => T
|
|
|
|
>c : C<string, number>
|
|
|
|
>foo5 : <T, U>(t: T, u: U) => T
|
|
|
|
|
|
|
|
var r9 = c.foo6(); // {}
|
|
|
|
>r9 : {}
|
|
|
|
>c.foo6() : {}
|
|
|
|
>c.foo6 : <T, U>() => T
|
|
|
|
>c : C<string, number>
|
|
|
|
>foo6 : <T, U>() => T
|
|
|
|
|
|
|
|
var r10 = c.foo7(''); // {}
|
|
|
|
>r10 : {}
|
|
|
|
>c.foo7('') : {}
|
|
|
|
>c.foo7 : <T, U>(u: U) => T
|
|
|
|
>c : C<string, number>
|
|
|
|
>foo7 : <T, U>(u: U) => T
|
|
|
|
|
|
|
|
var r11 = c.foo8(); // {}
|
|
|
|
>r11 : {}
|
|
|
|
>c.foo8() : {}
|
|
|
|
>c.foo8 : <T, U>() => T
|
|
|
|
>c : C<string, number>
|
|
|
|
>foo8 : <T, U>() => T
|
|
|
|
|
|
|
|
interface I<T, U> {
|
|
|
|
>I : I<T, U>
|
|
|
|
>T : T
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
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>(t: T, u: U): T;
|
|
|
|
>foo3 : <T>(t: T, u: U) => T
|
|
|
|
>T : T
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
foo4<U>(t: T, u: U): T;
|
|
|
|
>foo4 : <U>(t: T, u: U) => T
|
|
|
|
>U : U
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
foo5<T, U>(t: T, u: U): T;
|
|
|
|
>foo5 : <T, U>(t: T, u: U) => T
|
|
|
|
>T : T
|
|
|
|
>U : U
|
|
|
|
>t : T
|
|
|
|
>T : T
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
foo6<T, U>(): T;
|
|
|
|
>foo6 : <T, U>() => T
|
|
|
|
>T : T
|
|
|
|
>U : U
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
foo7<T, U>(u: U): T;
|
|
|
|
>foo7 : <T, U>(u: U) => T
|
|
|
|
>T : T
|
|
|
|
>U : U
|
|
|
|
>u : U
|
|
|
|
>U : U
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
foo8<T, U>(): T;
|
|
|
|
>foo8 : <T, U>() => T
|
|
|
|
>T : T
|
|
|
|
>U : U
|
|
|
|
>T : T
|
|
|
|
}
|
|
|
|
|
|
|
|
var i: I<string, number>;
|
|
|
|
>i : I<string, number>
|
2014-08-19 04:56:03 +02:00
|
|
|
>I : I<T, U>
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
var r4 = i.foo('', 1); // string
|
|
|
|
>r4 : string
|
|
|
|
>i.foo('', 1) : string
|
|
|
|
>i.foo : (t: string, u: number) => string
|
|
|
|
>i : I<string, number>
|
|
|
|
>foo : (t: string, u: number) => string
|
|
|
|
|
|
|
|
var r5 = i.foo2('', 1); // number
|
|
|
|
>r5 : number
|
|
|
|
>i.foo2('', 1) : number
|
|
|
|
>i.foo2 : (t: string, u: number) => number
|
|
|
|
>i : I<string, number>
|
|
|
|
>foo2 : (t: string, u: number) => number
|
|
|
|
|
|
|
|
var r6 = i.foo3(true, 1); // boolean
|
|
|
|
>r6 : boolean
|
|
|
|
>i.foo3(true, 1) : boolean
|
|
|
|
>i.foo3 : <T>(t: T, u: number) => T
|
|
|
|
>i : I<string, number>
|
|
|
|
>foo3 : <T>(t: T, u: number) => T
|
|
|
|
|
|
|
|
var r7 = i.foo4('', true); // string
|
|
|
|
>r7 : string
|
|
|
|
>i.foo4('', true) : string
|
|
|
|
>i.foo4 : <U>(t: string, u: U) => string
|
|
|
|
>i : I<string, number>
|
|
|
|
>foo4 : <U>(t: string, u: U) => string
|
|
|
|
|
|
|
|
var r8 = i.foo5(true, 1); // boolean
|
|
|
|
>r8 : boolean
|
|
|
|
>i.foo5(true, 1) : boolean
|
|
|
|
>i.foo5 : <T, U>(t: T, u: U) => T
|
|
|
|
>i : I<string, number>
|
|
|
|
>foo5 : <T, U>(t: T, u: U) => T
|
|
|
|
|
|
|
|
var r9 = i.foo6(); // {}
|
|
|
|
>r9 : {}
|
|
|
|
>i.foo6() : {}
|
|
|
|
>i.foo6 : <T, U>() => T
|
|
|
|
>i : I<string, number>
|
|
|
|
>foo6 : <T, U>() => T
|
|
|
|
|
|
|
|
var r10 = i.foo7(''); // {}
|
|
|
|
>r10 : {}
|
|
|
|
>i.foo7('') : {}
|
|
|
|
>i.foo7 : <T, U>(u: U) => T
|
|
|
|
>i : I<string, number>
|
|
|
|
>foo7 : <T, U>(u: U) => T
|
|
|
|
|
|
|
|
var r11 = i.foo8(); // {}
|
|
|
|
>r11 : {}
|
|
|
|
>i.foo8() : {}
|
|
|
|
>i.foo8 : <T, U>() => T
|
|
|
|
>i : I<string, number>
|
|
|
|
>foo8 : <T, U>() => T
|
|
|
|
|