2014-08-15 23:33:16 +02:00
|
|
|
=== tests/cases/conformance/interfaces/declarationMerging/twoMergedInterfacesWithDifferingOverloads.ts ===
|
|
|
|
// interfaces that merge must not have members that conflict
|
|
|
|
|
|
|
|
interface A {
|
|
|
|
>A : 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 {
|
|
|
|
>A : A
|
|
|
|
|
|
|
|
foo(x: Date): Date;
|
|
|
|
>foo : { (x: number): number; (x: string): string; (x: Date): Date; }
|
|
|
|
>x : Date
|
|
|
|
>Date : Date
|
|
|
|
>Date : Date
|
|
|
|
}
|
|
|
|
|
|
|
|
interface B<T> {
|
|
|
|
>B : B<T>
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
foo(x: T): number;
|
|
|
|
>foo : { (x: T): number; (x: string): string; (x: T): Date; (x: Date): string; }
|
|
|
|
>x : T
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
foo(x: string): string;
|
|
|
|
>foo : { (x: T): number; (x: string): string; (x: T): Date; (x: Date): string; }
|
|
|
|
>x : string
|
|
|
|
}
|
|
|
|
|
|
|
|
interface B<T> {
|
|
|
|
>B : B<T>
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
foo(x: T): Date;
|
|
|
|
>foo : { (x: T): number; (x: string): string; (x: T): Date; (x: Date): string; }
|
|
|
|
>x : T
|
|
|
|
>T : T
|
|
|
|
>Date : Date
|
|
|
|
|
|
|
|
foo(x: Date): string;
|
|
|
|
>foo : { (x: T): number; (x: string): string; (x: T): Date; (x: Date): string; }
|
|
|
|
>x : Date
|
|
|
|
>Date : Date
|
|
|
|
}
|
|
|
|
|
|
|
|
var b: B<boolean>;
|
|
|
|
>b : B<boolean>
|
2014-08-19 04:56:03 +02:00
|
|
|
>B : B<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
// add generic overload
|
|
|
|
interface C<T, U> {
|
|
|
|
>C : C<T, U>
|
|
|
|
>T : T
|
|
|
|
>U : 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
|
|
|
|
>T : T
|
|
|
|
>y : U
|
|
|
|
>U : 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> {
|
|
|
|
>C : C<T, U>
|
|
|
|
>T : T
|
|
|
|
>U : 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; }
|
|
|
|
>W : W
|
|
|
|
>x : W
|
|
|
|
>W : W
|
|
|
|
>y : W
|
|
|
|
>W : W
|
|
|
|
>W : W
|
|
|
|
}
|
|
|
|
|
|
|
|
var c: C<boolean, Date>;
|
|
|
|
>c : C<boolean, Date>
|
2014-08-19 04:56:03 +02:00
|
|
|
>C : C<T, U>
|
2014-08-15 23:33:16 +02:00
|
|
|
>Date : Date
|
|
|
|
|
|
|
|
var r2 = c.foo(1, 2); // number
|
|
|
|
>r2 : number
|
|
|
|
>c.foo(1, 2) : number
|
|
|
|
>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; }
|
|
|
|
|
|
|
|
// add generic overload that would be ambiguous
|
|
|
|
interface D<T, U> {
|
|
|
|
>D : D<T, U>
|
|
|
|
>T : T
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
a: T;
|
|
|
|
>a : T
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
b: U;
|
|
|
|
>b : U
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
foo<A>(x: A, y: A): U;
|
|
|
|
>foo : { <A>(x: A, y: A): U; <W>(x: W, y: W): T; }
|
|
|
|
>A : A
|
|
|
|
>x : A
|
|
|
|
>A : A
|
|
|
|
>y : A
|
|
|
|
>A : A
|
|
|
|
>U : U
|
|
|
|
}
|
|
|
|
|
|
|
|
interface D<T, U> {
|
|
|
|
>D : D<T, U>
|
|
|
|
>T : T
|
|
|
|
>U : U
|
|
|
|
|
|
|
|
foo<W>(x: W, y: W): T;
|
|
|
|
>foo : { <A>(x: A, y: A): U; <W>(x: W, y: W): T; }
|
|
|
|
>W : W
|
|
|
|
>x : W
|
|
|
|
>W : W
|
|
|
|
>y : W
|
|
|
|
>W : W
|
|
|
|
>T : T
|
|
|
|
}
|
|
|
|
|
|
|
|
var d: D<boolean, Date>;
|
|
|
|
>d : D<boolean, Date>
|
2014-08-19 04:56:03 +02:00
|
|
|
>D : D<T, U>
|
2014-08-15 23:33:16 +02:00
|
|
|
>Date : 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; }
|
|
|
|
|