diff --git a/tests/cases/conformance/types/union/unionTypeCallSignatures.ts b/tests/cases/conformance/types/union/unionTypeCallSignatures.ts index 1261de3299e..ca599329743 100644 --- a/tests/cases/conformance/types/union/unionTypeCallSignatures.ts +++ b/tests/cases/conformance/types/union/unionTypeCallSignatures.ts @@ -25,12 +25,12 @@ unionOfDifferentNumberOfSignatures(); // error - no call signatures unionOfDifferentNumberOfSignatures(10); // error - no call signatures unionOfDifferentNumberOfSignatures("hello"); // error - no call signatures - var unionWithDifferentParameterCount: { (a: string): string; } | { (a: string, b: number): number; } ; +var unionWithDifferentParameterCount: { (a: string): string; } | { (a: string, b: number): number; } ; unionWithDifferentParameterCount();// no call signature unionWithDifferentParameterCount("hello");// no call signature unionWithDifferentParameterCount("hello", 10);// no call signature - var unionWithOptionalParameter1: { (a: string, b?: number): string; } | { (a: string, b?: number): number; }; +var unionWithOptionalParameter1: { (a: string, b?: number): string; } | { (a: string, b?: number): number; }; strOrNum = unionWithOptionalParameter1('hello'); strOrNum = unionWithOptionalParameter1('hello', 10); strOrNum = unionWithOptionalParameter1('hello', "hello"); // error in parameter type @@ -43,7 +43,7 @@ strOrNum = unionWithOptionalParameter2('hello', "hello"); // error no call signa strOrNum = unionWithOptionalParameter2(); // error no call signature var unionWithOptionalParameter3: { (a: string, b?: number): string; } | { (a: string): number; }; -strOrNum = unionWithOptionalParameter3('hello'); // error no call signature +strOrNum = unionWithOptionalParameter3('hello'); strOrNum = unionWithOptionalParameter3('hello', 10); // error no call signature strOrNum = unionWithOptionalParameter3('hello', "hello"); // error no call signature strOrNum = unionWithOptionalParameter3(); // error no call signature @@ -63,8 +63,9 @@ strOrNum = unionWithRestParameter2('hello', "hello"); // error no call signature strOrNum = unionWithRestParameter2(); // error no call signature var unionWithRestParameter3: { (a: string, ...b: number[]): string; } | { (a: string): number }; -strOrNum = unionWithRestParameter3('hello'); // error no call signature +strOrNum = unionWithRestParameter3('hello'); strOrNum = unionWithRestParameter3('hello', 10); // error no call signature strOrNum = unionWithRestParameter3('hello', 10, 11); // error no call signature strOrNum = unionWithRestParameter3('hello', "hello"); // error no call signature -strOrNum = unionWithRestParameter3(); // error no call signature \ No newline at end of file +strOrNum = unionWithRestParameter3(); // error no call signature + diff --git a/tests/cases/conformance/types/union/unionTypeCallSignatures2.ts b/tests/cases/conformance/types/union/unionTypeCallSignatures2.ts new file mode 100644 index 00000000000..8095f649330 --- /dev/null +++ b/tests/cases/conformance/types/union/unionTypeCallSignatures2.ts @@ -0,0 +1,24 @@ +interface A { + (x: number): number; + (x: string, y?: string): boolean; + (x: Date): void; + (x: T[]): T[]; +} + +interface B { + (x: number): number; + (x: string): string; + (x: Date): void; + (x: T[]): T[]; +} + +interface C { + (x: string, ...y: string[]): number; + (x: number, s?: string): number; + (x: T[]): T[]; +} + +var f: A | B | C; +var n = f(42); // number +var s = f("abc"); // boolean | string | number +var a = f([true, false]); // boolean[]