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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
=== tests/cases/conformance/interfaces/declarationMerging/twoMergedInterfacesWithDifferingOverloads.ts ===
// interfaces that merge must not have members that conflict
interface A {
foo(x: number): number;
>foo : { (x: number): number; (x: string): string; (x: Date): Date; }
>x : number
foo(x: string): string;
>foo : { (x: number): number; (x: string): string; (x: Date): Date; }
>x : string
}
interface A {
foo(x: Date): Date;
>foo : { (x: number): number; (x: string): string; (x: Date): Date; }
>x : Date
}
interface B<T> {
foo(x: T): number;
>foo : { (x: T): number; (x: string): string; (x: T): Date; (x: Date): string; }
>x : T
foo(x: string): string;
>foo : { (x: T): number; (x: string): string; (x: T): Date; (x: Date): string; }
>x : string
}
interface B<T> {
foo(x: T): Date;
>foo : { (x: T): number; (x: string): string; (x: T): Date; (x: Date): string; }
>x : T
foo(x: Date): string;
>foo : { (x: T): number; (x: string): string; (x: T): Date; (x: Date): string; }
>x : Date
}
var b: B<boolean>;
>b : B<boolean>
var r = b.foo(true); // returns Date
>r : Date
>b.foo(true) : Date
>b.foo : { (x: boolean): number; (x: string): string; (x: boolean): Date; (x: Date): string; }
>b : B<boolean>
>foo : { (x: boolean): number; (x: string): string; (x: boolean): Date; (x: Date): string; }
>true : true
// add generic overload
interface C<T, U> {
foo(x: T, y: U): string;
>foo : { (x: T, y: U): string; (x: string, y: string): number; <W>(x: W, y: W): W; }
>x : T
>y : U
foo(x: string, y: string): number;
>foo : { (x: T, y: U): string; (x: string, y: string): number; <W>(x: W, y: W): W; }
>x : string
>y : string
}
interface C<T, U> {
foo<W>(x: W, y: W): W;
>foo : { (x: T, y: U): string; (x: string, y: string): number; <W>(x: W, y: W): W; }
>x : W
>y : W
}
var c: C<boolean, Date>;
>c : C<boolean, Date>
var r2 = c.foo(1, 2); // number
>r2 : number
>c.foo(1, 2) : 1 | 2
>c.foo : { (x: boolean, y: Date): string; (x: string, y: string): number; <W>(x: W, y: W): W; }
>c : C<boolean, Date>
>foo : { (x: boolean, y: Date): string; (x: string, y: string): number; <W>(x: W, y: W): W; }
>1 : 1
>2 : 2
// add generic overload that would be ambiguous
interface D<T, U> {
a: T;
>a : T
b: U;
>b : U
foo<A>(x: A, y: A): U;
>foo : { <A>(x: A, y: A): U; <W>(x: W, y: W): T; }
>x : A
>y : A
}
interface D<T, U> {
foo<W>(x: W, y: W): T;
>foo : { <A>(x: A, y: A): U; <W>(x: W, y: W): T; }
>x : W
>y : W
}
var d: D<boolean, Date>;
>d : D<boolean, Date>
var r3 = d.foo(1, 1); // boolean, last definition wins
>r3 : boolean
>d.foo(1, 1) : boolean
>d.foo : { <A>(x: A, y: A): Date; <W>(x: W, y: W): boolean; }
>d : D<boolean, Date>
>foo : { <A>(x: A, y: A): Date; <W>(x: W, y: W): boolean; }
>1 : 1
>1 : 1
|