From bc2b1050371c9aa0998b5d1e69cc6ff3ddbabea3 Mon Sep 17 00:00:00 2001 From: erictsangx Date: Thu, 26 Nov 2015 18:33:56 +0800 Subject: [PATCH] add tests for the issue --- .../types/union/unionTypeCallSignatures.ts | 14 +++++++------- .../types/union/unionTypeCallSignatures5.ts | 12 ++++++++++++ .../conformance/types/union/unionTypeMembers.ts | 3 +-- 3 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 tests/cases/conformance/types/union/unionTypeCallSignatures5.ts diff --git a/tests/cases/conformance/types/union/unionTypeCallSignatures.ts b/tests/cases/conformance/types/union/unionTypeCallSignatures.ts index a25d27d9a29..c15fa69ea91 100644 --- a/tests/cases/conformance/types/union/unionTypeCallSignatures.ts +++ b/tests/cases/conformance/types/union/unionTypeCallSignatures.ts @@ -16,9 +16,9 @@ unionOfDifferentReturnType1(true); // error in type of parameter unionOfDifferentReturnType1(); // error missing parameter var unionOfDifferentParameterTypes: { (a: number): number; } | { (a: string): Date; }; -unionOfDifferentParameterTypes(10);// error - no call signatures -unionOfDifferentParameterTypes("hello");// error - no call signatures -unionOfDifferentParameterTypes();// error - no call signatures +unionOfDifferentParameterTypes(10); //no error +unionOfDifferentParameterTypes("hello"); //no error +unionOfDifferentParameterTypes(); //error TS2346 var unionOfDifferentNumberOfSignatures: { (a: number): number; } | { (a: number): Date; (a: string): boolean; }; unionOfDifferentNumberOfSignatures(); // error - no call signatures @@ -26,9 +26,9 @@ unionOfDifferentNumberOfSignatures(10); // error - no call signatures unionOfDifferentNumberOfSignatures("hello"); // error - no call signatures 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 +unionWithDifferentParameterCount(); //error TS2346 +unionWithDifferentParameterCount("hello"); //no error +unionWithDifferentParameterCount("hello", 10); //no error var unionWithOptionalParameter1: { (a: string, b?: number): string; } | { (a: string, b?: number): number; }; strOrNum = unionWithOptionalParameter1('hello'); @@ -71,4 +71,4 @@ strOrNum = unionWithRestParameter3(); // error no call signature var unionWithRestParameter4: { (...a: string[]): string; } | { (a: string, b: string): number; }; strOrNum = unionWithRestParameter4("hello"); // error supplied parameters do not match any call signature -strOrNum = unionWithRestParameter4("hello", "world"); +strOrNum = unionWithRestParameter4("hello", "world"); \ No newline at end of file diff --git a/tests/cases/conformance/types/union/unionTypeCallSignatures5.ts b/tests/cases/conformance/types/union/unionTypeCallSignatures5.ts new file mode 100644 index 00000000000..75626151807 --- /dev/null +++ b/tests/cases/conformance/types/union/unionTypeCallSignatures5.ts @@ -0,0 +1,12 @@ +interface A { + (number) : number; +} + +var f1: string | number; +f1(); //error TS2658 + +var f2: string | A; +f2(); //error TS2658 + +var f3: string[] | number[]; +f3.map(value=>value); //should not throw TS2349 \ No newline at end of file diff --git a/tests/cases/conformance/types/union/unionTypeMembers.ts b/tests/cases/conformance/types/union/unionTypeMembers.ts index 73c6867e9ac..00dc7562ccf 100644 --- a/tests/cases/conformance/types/union/unionTypeMembers.ts +++ b/tests/cases/conformance/types/union/unionTypeMembers.ts @@ -41,8 +41,7 @@ str = x.commonMethodType(str); // (a: string) => string so result should be stri strOrNum = x.commonPropertyDifferenType; strOrNum = x.commonMethodDifferentReturnType(str); // string | union x.commonMethodDifferentParameterType; // No error - property exists -x.commonMethodDifferentParameterType(strOrNum); // error - no call signatures because the type of this property is ((a: string) => string) | (a: number) => number - // and the call signatures arent identical +x.commonMethodDifferentParameterType(strOrNum); //error - TS2345 num = x.commonMethodWithTypeParameter(num); num = x.commonMethodWithOwnTypeParameter(num); str = x.commonMethodWithOwnTypeParameter(str);