1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
=== tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts ===
interface A { x }
>x : any
interface B { x; y }
>x : any
>y : any
interface C { z }
>z : any
interface D { q }
>q : any
class G<T extends A> {
>G : G<T>
constructor(x: T) { }
>x : T
}
declare function foo(arg: (x: D) => number): string;
>foo : { (arg: (x: D) => number): string; (arg: (x: C) => any): string; (arg: (x: B) => any): number; }
>arg : (x: D) => number
>x : D
declare function foo(arg: (x: C) => any): string;
>foo : { (arg: (x: D) => number): string; (arg: (x: C) => any): string; (arg: (x: B) => any): number; }
>arg : (x: C) => any
>x : C
declare function foo(arg: (x: B) => any): number;
>foo : { (arg: (x: D) => number): string; (arg: (x: C) => any): string; (arg: (x: B) => any): number; }
>arg : (x: B) => any
>x : B
var result: number = foo(x => new G(x)); // x has type D, new G(x) fails, so first overload is picked.
>result : number
>foo(x => new G(x)) : never
>foo : { (arg: (x: D) => number): string; (arg: (x: C) => any): string; (arg: (x: B) => any): number; }
>x => new G(x) : (x: D) => G<A>
>x : D
>new G(x) : G<A>
>G : typeof G
>x : D
var result2: number = foo(x => new G<typeof x>(x)); // x has type D, new G(x) fails, so first overload is picked.
>result2 : number
>foo(x => new G<typeof x>(x)) : never
>foo : { (arg: (x: D) => number): string; (arg: (x: C) => any): string; (arg: (x: B) => any): number; }
>x => new G<typeof x>(x) : (x: D) => G<D>
>x : D
>new G<typeof x>(x) : G<D>
>G : typeof G
>x : D
>x : D
var result3: string = foo(x => { // x has type D
>result3 : string
>foo(x => { // x has type D var y: G<typeof x>; // error that D does not satisfy constraint, y is of type G<D>, entire call to foo is an error return y;}) : never
>foo : { (arg: (x: D) => number): string; (arg: (x: C) => any): string; (arg: (x: B) => any): number; }
>x => { // x has type D var y: G<typeof x>; // error that D does not satisfy constraint, y is of type G<D>, entire call to foo is an error return y;} : (x: D) => G<D>
>x : D
var y: G<typeof x>; // error that D does not satisfy constraint, y is of type G<D>, entire call to foo is an error
>y : G<D>
>x : D
return y;
>y : G<D>
});
|