183 lines
6.3 KiB
Plaintext
183 lines
6.3 KiB
Plaintext
|
=== 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 {
|
||
|
>NonGenericParameter : typeof NonGenericParameter
|
||
|
|
||
|
var a: {
|
||
|
>a : { (x: boolean): boolean; (x: string): string; }
|
||
|
|
||
|
(x: boolean): boolean;
|
||
|
>x : boolean
|
||
|
|
||
|
(x: string): string;
|
||
|
>x : string
|
||
|
}
|
||
|
|
||
|
function foo4(cb: typeof a) {
|
||
|
>foo4 : (cb: { (x: boolean): boolean; (x: string): string; }) => { (x: boolean): boolean; (x: string): string; }
|
||
|
>cb : { (x: boolean): boolean; (x: string): string; }
|
||
|
>a : { (x: boolean): boolean; (x: string): string; }
|
||
|
|
||
|
return cb;
|
||
|
>cb : { (x: boolean): boolean; (x: string): string; }
|
||
|
}
|
||
|
|
||
|
var r = foo4(a);
|
||
|
>r : { (x: boolean): boolean; (x: string): string; }
|
||
|
>foo4(a) : { (x: boolean): boolean; (x: string): string; }
|
||
|
>foo4 : (cb: { (x: boolean): boolean; (x: string): string; }) => { (x: boolean): boolean; (x: string): string; }
|
||
|
>a : { (x: boolean): boolean; (x: string): string; }
|
||
|
|
||
|
var r2 = foo4(<T>(x: T) => x);
|
||
|
>r2 : { (x: boolean): boolean; (x: string): string; }
|
||
|
>foo4(<T>(x: T) => x) : { (x: boolean): boolean; (x: string): string; }
|
||
|
>foo4 : (cb: { (x: boolean): boolean; (x: string): string; }) => { (x: boolean): boolean; (x: string): string; }
|
||
|
><T>(x: T) => x : <T>(x: T) => T
|
||
|
>T : T
|
||
|
>x : T
|
||
|
>T : T
|
||
|
>x : T
|
||
|
|
||
|
var r4 = foo4(x => x);
|
||
|
>r4 : { (x: boolean): boolean; (x: string): string; }
|
||
|
>foo4(x => x) : { (x: boolean): boolean; (x: string): string; }
|
||
|
>foo4 : (cb: { (x: boolean): boolean; (x: string): string; }) => { (x: boolean): boolean; (x: string): string; }
|
||
|
>x => x : (x: any) => any
|
||
|
>x : any
|
||
|
>x : any
|
||
|
}
|
||
|
|
||
|
module GenericParameter {
|
||
|
>GenericParameter : typeof GenericParameter
|
||
|
|
||
|
function foo5<T>(cb: { (x: T): string; (x: number): T }) {
|
||
|
>foo5 : <T>(cb: { (x: T): string; (x: number): T; }) => { (x: T): string; (x: number): T; }
|
||
|
>T : T
|
||
|
>cb : { (x: T): string; (x: number): T; }
|
||
|
>x : T
|
||
|
>T : T
|
||
|
>x : number
|
||
|
>T : T
|
||
|
|
||
|
return cb;
|
||
|
>cb : { (x: T): string; (x: number): T; }
|
||
|
}
|
||
|
|
||
|
var r5 = foo5(x => x); // any => string (+1 overload) [inferences are made for T, but lambda not contextually typed]. T is any
|
||
|
>r5 : { (x: any): string; (x: number): any; }
|
||
|
>foo5(x => x) : { (x: any): string; (x: number): any; }
|
||
|
>foo5 : <T>(cb: { (x: T): string; (x: number): T; }) => { (x: T): string; (x: number): T; }
|
||
|
>x => x : (x: any) => any
|
||
|
>x : any
|
||
|
>x : any
|
||
|
|
||
|
var a: { <T>(x: T): string; <T>(x: number): T; }
|
||
|
>a : { <T>(x: T): string; <T>(x: number): T; }
|
||
|
>T : T
|
||
|
>x : T
|
||
|
>T : T
|
||
|
>T : T
|
||
|
>x : number
|
||
|
>T : T
|
||
|
|
||
|
var r7 = foo5(a); // any => string (+1 overload)
|
||
|
>r7 : { (x: any): string; (x: number): any; }
|
||
|
>foo5(a) : { (x: any): string; (x: number): any; }
|
||
|
>foo5 : <T>(cb: { (x: T): string; (x: number): T; }) => { (x: T): string; (x: number): T; }
|
||
|
>a : { <T>(x: T): string; <T>(x: number): T; }
|
||
|
|
||
|
function foo6<T>(cb: { (x: T): string; (x: T, y?: T): string }) {
|
||
|
>foo6 : <T>(cb: { (x: T): string; (x: T, y?: T): string; }) => { (x: T): string; (x: T, y?: T): string; }
|
||
|
>T : T
|
||
|
>cb : { (x: T): string; (x: T, y?: T): string; }
|
||
|
>x : T
|
||
|
>T : T
|
||
|
>x : T
|
||
|
>T : T
|
||
|
>y : T
|
||
|
>T : T
|
||
|
|
||
|
return cb;
|
||
|
>cb : { (x: T): string; (x: T, y?: T): string; }
|
||
|
}
|
||
|
|
||
|
var r8 = foo6(x => x); // any => string (+1 overload) [inferences are made for T, but lambda not contextually typed]. T is any
|
||
|
>r8 : { (x: any): string; (x: any, y?: any): string; }
|
||
|
>foo6(x => x) : { (x: any): string; (x: any, y?: any): string; }
|
||
|
>foo6 : <T>(cb: { (x: T): string; (x: T, y?: T): string; }) => { (x: T): string; (x: T, y?: T): string; }
|
||
|
>x => x : (x: any) => any
|
||
|
>x : any
|
||
|
>x : any
|
||
|
|
||
|
var r9 = foo6(<T>(x: T) => ''); // any => string (+1 overload)
|
||
|
>r9 : { (x: any): string; (x: any, y?: any): string; }
|
||
|
>foo6(<T>(x: T) => '') : { (x: any): string; (x: any, y?: any): string; }
|
||
|
>foo6 : <T>(cb: { (x: T): string; (x: T, y?: T): string; }) => { (x: T): string; (x: T, y?: T): string; }
|
||
|
><T>(x: T) => '' : <T>(x: T) => string
|
||
|
>T : T
|
||
|
>x : T
|
||
|
>T : T
|
||
|
|
||
|
var r11 = foo6(<T>(x: T, y?: T) => ''); // any => string (+1 overload)
|
||
|
>r11 : { (x: any): string; (x: any, y?: any): string; }
|
||
|
>foo6(<T>(x: T, y?: T) => '') : { (x: any): string; (x: any, y?: any): string; }
|
||
|
>foo6 : <T>(cb: { (x: T): string; (x: T, y?: T): string; }) => { (x: T): string; (x: T, y?: T): string; }
|
||
|
><T>(x: T, y?: T) => '' : <T>(x: T, y?: T) => string
|
||
|
>T : T
|
||
|
>x : T
|
||
|
>T : T
|
||
|
>y : T
|
||
|
>T : T
|
||
|
|
||
|
function foo7<T>(x:T, cb: { (x: T): string; (x: T, y?: T): string }) {
|
||
|
>foo7 : <T>(x: T, cb: { (x: T): string; (x: T, y?: T): string; }) => { (x: T): string; (x: T, y?: T): string; }
|
||
|
>T : T
|
||
|
>x : T
|
||
|
>T : T
|
||
|
>cb : { (x: T): string; (x: T, y?: T): string; }
|
||
|
>x : T
|
||
|
>T : T
|
||
|
>x : T
|
||
|
>T : T
|
||
|
>y : T
|
||
|
>T : T
|
||
|
|
||
|
return cb;
|
||
|
>cb : { (x: T): string; (x: T, y?: T): string; }
|
||
|
}
|
||
|
|
||
|
var r12 = foo7(1, (x) => x); // any => string (+1 overload) [inferences are made for T, but lambda not contextually typed]
|
||
|
>r12 : { (x: any): string; (x: any, y?: any): string; }
|
||
|
>foo7(1, (x) => x) : { (x: any): string; (x: any, y?: any): string; }
|
||
|
>foo7 : <T>(x: T, cb: { (x: T): string; (x: T, y?: T): string; }) => { (x: T): string; (x: T, y?: T): string; }
|
||
|
>(x) => x : (x: any) => any
|
||
|
>x : any
|
||
|
>x : any
|
||
|
|
||
|
var r13 = foo7(1, <T>(x: T) => ''); // any => string (+1 overload) [inferences are made for T, but lambda not contextually typed]
|
||
|
>r13 : { (x: any): string; (x: any, y?: any): string; }
|
||
|
>foo7(1, <T>(x: T) => '') : { (x: any): string; (x: any, y?: any): string; }
|
||
|
>foo7 : <T>(x: T, cb: { (x: T): string; (x: T, y?: T): string; }) => { (x: T): string; (x: T, y?: T): string; }
|
||
|
><T>(x: T) => '' : <T>(x: T) => string
|
||
|
>T : T
|
||
|
>x : T
|
||
|
>T : T
|
||
|
|
||
|
var a: { <T>(x: T): string; <T>(x: number): T; }
|
||
|
>a : { <T>(x: T): string; <T>(x: number): T; }
|
||
|
>T : T
|
||
|
>x : T
|
||
|
>T : T
|
||
|
>T : T
|
||
|
>x : number
|
||
|
>T : T
|
||
|
|
||
|
var r14 = foo7(1, a); // any => string (+1 overload) [inferences are made for T, but lambda not contextually typed]
|
||
|
>r14 : { (x: any): string; (x: any, y?: any): string; }
|
||
|
>foo7(1, a) : { (x: any): string; (x: any, y?: any): string; }
|
||
|
>foo7 : <T>(x: T, cb: { (x: T): string; (x: T, y?: T): string; }) => { (x: T): string; (x: T, y?: T): string; }
|
||
|
>a : { <T>(x: T): string; <T>(x: number): T; }
|
||
|
}
|