TypeScript/tests/baselines/reference/genericCallWithOverloadedFunctionTypedArguments.types

189 lines
14 KiB
Plaintext
Raw Normal View History

2014-08-15 23:33:16 +02:00
=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedFunctionTypedArguments.ts ===
// Function typed arguments with multiple signatures must be passed an implementation that matches all of them
// Inferences are made quadratic-pairwise to and from these overload sets
module NonGenericParameter {
2015-04-13 23:01:57 +02:00
>NonGenericParameter : typeof NonGenericParameter, Symbol(NonGenericParameter, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 0, 0))
2014-08-15 23:33:16 +02:00
var a: {
2015-04-13 23:01:57 +02:00
>a : { (x: boolean): boolean; (x: string): string; }, Symbol(a, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 4, 7))
2014-08-15 23:33:16 +02:00
(x: boolean): boolean;
2015-04-13 23:01:57 +02:00
>x : boolean, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 5, 9))
2014-08-15 23:33:16 +02:00
(x: string): string;
2015-04-13 23:01:57 +02:00
>x : string, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 6, 9))
2014-08-15 23:33:16 +02:00
}
function foo4(cb: typeof a) {
2015-04-13 23:01:57 +02:00
>foo4 : (cb: { (x: boolean): boolean; (x: string): string; }) => { (x: boolean): boolean; (x: string): string; }, Symbol(foo4, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 7, 5))
>cb : { (x: boolean): boolean; (x: string): string; }, Symbol(cb, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 9, 18))
>a : { (x: boolean): boolean; (x: string): string; }, Symbol(a, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 4, 7))
2014-08-15 23:33:16 +02:00
return cb;
2015-04-13 23:01:57 +02:00
>cb : { (x: boolean): boolean; (x: string): string; }, Symbol(cb, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 9, 18))
2014-08-15 23:33:16 +02:00
}
var r = foo4(a);
2015-04-13 23:01:57 +02:00
>r : { (x: boolean): boolean; (x: string): string; }, Symbol(r, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 13, 7))
2014-08-15 23:33:16 +02:00
>foo4(a) : { (x: boolean): boolean; (x: string): string; }
2015-04-13 23:01:57 +02:00
>foo4 : (cb: { (x: boolean): boolean; (x: string): string; }) => { (x: boolean): boolean; (x: string): string; }, Symbol(foo4, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 7, 5))
>a : { (x: boolean): boolean; (x: string): string; }, Symbol(a, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 4, 7))
2014-08-15 23:33:16 +02:00
var r2 = foo4(<T>(x: T) => x);
2015-04-13 23:01:57 +02:00
>r2 : { (x: boolean): boolean; (x: string): string; }, Symbol(r2, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 14, 7))
2014-08-15 23:33:16 +02:00
>foo4(<T>(x: T) => x) : { (x: boolean): boolean; (x: string): string; }
2015-04-13 23:01:57 +02:00
>foo4 : (cb: { (x: boolean): boolean; (x: string): string; }) => { (x: boolean): boolean; (x: string): string; }, Symbol(foo4, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 7, 5))
2014-08-15 23:33:16 +02:00
><T>(x: T) => x : <T>(x: T) => T
2015-04-13 23:01:57 +02:00
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 14, 19))
>x : T, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 14, 22))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 14, 19))
>x : T, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 14, 22))
2014-08-15 23:33:16 +02:00
var r4 = foo4(x => x);
2015-04-13 23:01:57 +02:00
>r4 : { (x: boolean): boolean; (x: string): string; }, Symbol(r4, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 15, 7))
2014-08-15 23:33:16 +02:00
>foo4(x => x) : { (x: boolean): boolean; (x: string): string; }
2015-04-13 23:01:57 +02:00
>foo4 : (cb: { (x: boolean): boolean; (x: string): string; }) => { (x: boolean): boolean; (x: string): string; }, Symbol(foo4, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 7, 5))
2014-08-15 23:33:16 +02:00
>x => x : (x: any) => any
2015-04-13 23:01:57 +02:00
>x : any, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 15, 18))
>x : any, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 15, 18))
2014-08-15 23:33:16 +02:00
}
module GenericParameter {
2015-04-13 23:01:57 +02:00
>GenericParameter : typeof GenericParameter, Symbol(GenericParameter, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 16, 1))
2014-08-15 23:33:16 +02:00
function foo5<T>(cb: { (x: T): string; (x: number): T }) {
2015-04-13 23:01:57 +02:00
>foo5 : <T>(cb: { (x: T): string; (x: number): T; }) => { (x: T): string; (x: number): T; }, Symbol(foo5, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 18, 25))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 19, 18))
>cb : { (x: T): string; (x: number): T; }, Symbol(cb, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 19, 21))
>x : T, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 19, 28))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 19, 18))
>x : number, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 19, 44))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 19, 18))
2014-08-15 23:33:16 +02:00
return cb;
2015-04-13 23:01:57 +02:00
>cb : { (x: T): string; (x: number): T; }, Symbol(cb, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 19, 21))
2014-08-15 23:33:16 +02:00
}
var r5 = foo5(x => x); // any => string (+1 overload) [inferences are made for T, but lambda not contextually typed]. T is any
2015-04-13 23:01:57 +02:00
>r5 : { (x: any): string; (x: number): any; }, Symbol(r5, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 23, 7))
2014-08-15 23:33:16 +02:00
>foo5(x => x) : { (x: any): string; (x: number): any; }
2015-04-13 23:01:57 +02:00
>foo5 : <T>(cb: { (x: T): string; (x: number): T; }) => { (x: T): string; (x: number): T; }, Symbol(foo5, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 18, 25))
2014-08-15 23:33:16 +02:00
>x => x : (x: any) => any
2015-04-13 23:01:57 +02:00
>x : any, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 23, 18))
>x : any, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 23, 18))
2014-08-15 23:33:16 +02:00
var a: { <T>(x: T): string; <T>(x: number): T; }
2015-04-13 23:01:57 +02:00
>a : { <T>(x: T): string; <T>(x: number): T; }, Symbol(a, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 24, 7), Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 41, 7))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 24, 14))
>x : T, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 24, 17))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 24, 14))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 24, 33))
>x : number, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 24, 36))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 24, 33))
2014-08-15 23:33:16 +02:00
var r7 = foo5(a); // any => string (+1 overload)
2015-04-13 23:01:57 +02:00
>r7 : { (x: any): string; (x: number): any; }, Symbol(r7, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 25, 7))
2014-08-15 23:33:16 +02:00
>foo5(a) : { (x: any): string; (x: number): any; }
2015-04-13 23:01:57 +02:00
>foo5 : <T>(cb: { (x: T): string; (x: number): T; }) => { (x: T): string; (x: number): T; }, Symbol(foo5, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 18, 25))
>a : { <T>(x: T): string; <T>(x: number): T; }, Symbol(a, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 24, 7), Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 41, 7))
2014-08-15 23:33:16 +02:00
function foo6<T>(cb: { (x: T): string; (x: T, y?: T): string }) {
2015-04-13 23:01:57 +02:00
>foo6 : <T>(cb: { (x: T): string; (x: T, y?: T): string; }) => { (x: T): string; (x: T, y?: T): string; }, Symbol(foo6, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 25, 21))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 27, 18))
>cb : { (x: T): string; (x: T, y?: T): string; }, Symbol(cb, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 27, 21))
>x : T, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 27, 28))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 27, 18))
>x : T, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 27, 44))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 27, 18))
>y : T, Symbol(y, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 27, 49))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 27, 18))
2014-08-15 23:33:16 +02:00
return cb;
2015-04-13 23:01:57 +02:00
>cb : { (x: T): string; (x: T, y?: T): string; }, Symbol(cb, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 27, 21))
2014-08-15 23:33:16 +02:00
}
var r8 = foo6(x => x); // any => string (+1 overload) [inferences are made for T, but lambda not contextually typed]. T is any
2015-04-13 23:01:57 +02:00
>r8 : { (x: any): string; (x: any, y?: any): string; }, Symbol(r8, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 31, 7))
2014-08-15 23:33:16 +02:00
>foo6(x => x) : { (x: any): string; (x: any, y?: any): string; }
2015-04-13 23:01:57 +02:00
>foo6 : <T>(cb: { (x: T): string; (x: T, y?: T): string; }) => { (x: T): string; (x: T, y?: T): string; }, Symbol(foo6, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 25, 21))
2014-08-15 23:33:16 +02:00
>x => x : (x: any) => any
2015-04-13 23:01:57 +02:00
>x : any, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 31, 18))
>x : any, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 31, 18))
2014-08-15 23:33:16 +02:00
var r9 = foo6(<T>(x: T) => ''); // any => string (+1 overload)
2015-04-13 23:01:57 +02:00
>r9 : { (x: any): string; (x: any, y?: any): string; }, Symbol(r9, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 32, 7))
2014-08-15 23:33:16 +02:00
>foo6(<T>(x: T) => '') : { (x: any): string; (x: any, y?: any): string; }
2015-04-13 23:01:57 +02:00
>foo6 : <T>(cb: { (x: T): string; (x: T, y?: T): string; }) => { (x: T): string; (x: T, y?: T): string; }, Symbol(foo6, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 25, 21))
2014-08-15 23:33:16 +02:00
><T>(x: T) => '' : <T>(x: T) => string
2015-04-13 23:01:57 +02:00
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 32, 19))
>x : T, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 32, 22))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 32, 19))
2015-04-13 21:36:11 +02:00
>'' : string
2014-08-15 23:33:16 +02:00
var r11 = foo6(<T>(x: T, y?: T) => ''); // any => string (+1 overload)
2015-04-13 23:01:57 +02:00
>r11 : { (x: any): string; (x: any, y?: any): string; }, Symbol(r11, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 33, 7))
2014-08-15 23:33:16 +02:00
>foo6(<T>(x: T, y?: T) => '') : { (x: any): string; (x: any, y?: any): string; }
2015-04-13 23:01:57 +02:00
>foo6 : <T>(cb: { (x: T): string; (x: T, y?: T): string; }) => { (x: T): string; (x: T, y?: T): string; }, Symbol(foo6, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 25, 21))
2014-08-15 23:33:16 +02:00
><T>(x: T, y?: T) => '' : <T>(x: T, y?: T) => string
2015-04-13 23:01:57 +02:00
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 33, 20))
>x : T, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 33, 23))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 33, 20))
>y : T, Symbol(y, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 33, 28))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 33, 20))
2015-04-13 21:36:11 +02:00
>'' : string
2014-08-15 23:33:16 +02:00
function foo7<T>(x:T, cb: { (x: T): string; (x: T, y?: T): string }) {
2015-04-13 23:01:57 +02:00
>foo7 : <T>(x: T, cb: { (x: T): string; (x: T, y?: T): string; }) => { (x: T): string; (x: T, y?: T): string; }, Symbol(foo7, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 33, 43))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 35, 18))
>x : T, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 35, 21))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 35, 18))
>cb : { (x: T): string; (x: T, y?: T): string; }, Symbol(cb, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 35, 25))
>x : T, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 35, 33))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 35, 18))
>x : T, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 35, 49))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 35, 18))
>y : T, Symbol(y, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 35, 54))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 35, 18))
2014-08-15 23:33:16 +02:00
return cb;
2015-04-13 23:01:57 +02:00
>cb : { (x: T): string; (x: T, y?: T): string; }, Symbol(cb, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 35, 25))
2014-08-15 23:33:16 +02:00
}
var r12 = foo7(1, (x) => x); // any => string (+1 overload) [inferences are made for T, but lambda not contextually typed]
2015-04-13 23:01:57 +02:00
>r12 : { (x: any): string; (x: any, y?: any): string; }, Symbol(r12, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 39, 7))
2014-08-15 23:33:16 +02:00
>foo7(1, (x) => x) : { (x: any): string; (x: any, y?: any): string; }
2015-04-13 23:01:57 +02:00
>foo7 : <T>(x: T, cb: { (x: T): string; (x: T, y?: T): string; }) => { (x: T): string; (x: T, y?: T): string; }, Symbol(foo7, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 33, 43))
2015-04-13 21:36:11 +02:00
>1 : number
2014-08-15 23:33:16 +02:00
>(x) => x : (x: any) => any
2015-04-13 23:01:57 +02:00
>x : any, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 39, 23))
>x : any, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 39, 23))
2014-08-15 23:33:16 +02:00
var r13 = foo7(1, <T>(x: T) => ''); // any => string (+1 overload) [inferences are made for T, but lambda not contextually typed]
2015-04-13 23:01:57 +02:00
>r13 : { (x: any): string; (x: any, y?: any): string; }, Symbol(r13, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 40, 7))
2014-08-15 23:33:16 +02:00
>foo7(1, <T>(x: T) => '') : { (x: any): string; (x: any, y?: any): string; }
2015-04-13 23:01:57 +02:00
>foo7 : <T>(x: T, cb: { (x: T): string; (x: T, y?: T): string; }) => { (x: T): string; (x: T, y?: T): string; }, Symbol(foo7, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 33, 43))
2015-04-13 21:36:11 +02:00
>1 : number
2014-08-15 23:33:16 +02:00
><T>(x: T) => '' : <T>(x: T) => string
2015-04-13 23:01:57 +02:00
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 40, 23))
>x : T, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 40, 26))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 40, 23))
2015-04-13 21:36:11 +02:00
>'' : string
2014-08-15 23:33:16 +02:00
var a: { <T>(x: T): string; <T>(x: number): T; }
2015-04-13 23:01:57 +02:00
>a : { <T>(x: T): string; <T>(x: number): T; }, Symbol(a, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 24, 7), Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 41, 7))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 41, 14))
>x : T, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 41, 17))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 41, 14))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 41, 33))
>x : number, Symbol(x, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 41, 36))
>T : T, Symbol(T, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 41, 33))
2014-08-15 23:33:16 +02:00
var r14 = foo7(1, a); // any => string (+1 overload) [inferences are made for T, but lambda not contextually typed]
2015-04-13 23:01:57 +02:00
>r14 : { (x: any): string; (x: any, y?: any): string; }, Symbol(r14, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 42, 7))
2014-08-15 23:33:16 +02:00
>foo7(1, a) : { (x: any): string; (x: any, y?: any): string; }
2015-04-13 23:01:57 +02:00
>foo7 : <T>(x: T, cb: { (x: T): string; (x: T, y?: T): string; }) => { (x: T): string; (x: T, y?: T): string; }, Symbol(foo7, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 33, 43))
2015-04-13 21:36:11 +02:00
>1 : number
2015-04-13 23:01:57 +02:00
>a : { <T>(x: T): string; <T>(x: number): T; }, Symbol(a, Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 24, 7), Decl(genericCallWithOverloadedFunctionTypedArguments.ts, 41, 7))
2014-08-15 23:33:16 +02:00
}