Tests for union of call signatures
If each type in U has call signatures and the sets of call signatures are identical ignoring return types, U has the same set of call signatures, but with return types that are unions of the return types of the respective call signatures from each type in U.
This commit is contained in:
parent
357bd87612
commit
2b8342bd79
3 changed files with 380 additions and 0 deletions
178
tests/baselines/reference/unionTypeCallSignatures.errors.txt
Normal file
178
tests/baselines/reference/unionTypeCallSignatures.errors.txt
Normal file
|
@ -0,0 +1,178 @@
|
|||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(9,43): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(10,29): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(15,29): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(16,1): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(19,1): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(20,1): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(21,1): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(24,1): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(25,1): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(26,1): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(29,1): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(30,1): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(31,1): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(36,49): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(37,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(40,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(41,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(42,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(43,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(46,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(47,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(48,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(49,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(55,45): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(56,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(59,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(60,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(61,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(62,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(63,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(66,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(67,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(68,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(69,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(70,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/union/unionTypeCallSignatures.ts (35 errors) ====
|
||||
var numOrDate: number | Date;
|
||||
var strOrBoolean: string | boolean;
|
||||
var strOrNum: string | number;
|
||||
|
||||
// If each type in U has call signatures and the sets of call signatures are identical ignoring return types,
|
||||
// U has the same set of call signatures, but with return types that are unions of the return types of the respective call signatures from each type in U.
|
||||
var unionOfDifferentReturnType: { (a: number): number; } | { (a: number): Date; };
|
||||
numOrDate = unionOfDifferentReturnType(10);
|
||||
strOrBoolean = unionOfDifferentReturnType("hello"); // error
|
||||
~~~~~~~
|
||||
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
||||
unionOfDifferentReturnType1(true); // error in type of parameter
|
||||
~~~~
|
||||
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
|
||||
|
||||
var unionOfDifferentReturnType1: { (a: number): number; (a: string): string; } | { (a: number): Date; (a: string): boolean; };
|
||||
numOrDate = unionOfDifferentReturnType1(10);
|
||||
strOrBoolean = unionOfDifferentReturnType1("hello");
|
||||
unionOfDifferentReturnType1(true); // error in type of parameter
|
||||
~~~~
|
||||
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
|
||||
unionOfDifferentReturnType1(); // error missing parameter
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
|
||||
var unionOfDifferentParameterTypes: { (a: number): number; } | { (a: string): Date; };
|
||||
unionOfDifferentParameterTypes(10);// error - no call signatures
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
unionOfDifferentParameterTypes("hello");// error - no call signatures
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
unionOfDifferentParameterTypes();// error - no call signatures
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
|
||||
var unionOfDifferentNumberOfSignatures: { (a: number): number; } | { (a: number): Date; (a: string): boolean; };
|
||||
unionOfDifferentNumberOfSignatures(); // error - no call signatures
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
unionOfDifferentNumberOfSignatures(10); // error - no call signatures
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
unionOfDifferentNumberOfSignatures("hello"); // error - no call signatures
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
|
||||
var unionWithDifferentParameterCount: { (a: string): string; } | { (a: string, b: number): number; } ;
|
||||
unionWithDifferentParameterCount();// no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
unionWithDifferentParameterCount("hello");// no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
unionWithDifferentParameterCount("hello", 10);// no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
|
||||
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
|
||||
~~~~~~~
|
||||
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
||||
strOrNum = unionWithOptionalParameter1(); // error
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
|
||||
var unionWithOptionalParameter2: { (a: string, b?: number): string; } | { (a: string, b: number): number };
|
||||
strOrNum = unionWithOptionalParameter2('hello'); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
strOrNum = unionWithOptionalParameter2('hello', 10); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
strOrNum = unionWithOptionalParameter2('hello', "hello"); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
strOrNum = unionWithOptionalParameter2(); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
|
||||
var unionWithOptionalParameter3: { (a: string, b?: number): string; } | { (a: string): number; };
|
||||
strOrNum = unionWithOptionalParameter3('hello'); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
strOrNum = unionWithOptionalParameter3('hello', 10); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
strOrNum = unionWithOptionalParameter3('hello', "hello"); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
strOrNum = unionWithOptionalParameter3(); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
|
||||
var unionWithRestParameter1: { (a: string, ...b: number[]): string; } | { (a: string, ...b: number[]): number };
|
||||
strOrNum = unionWithRestParameter1('hello');
|
||||
strOrNum = unionWithRestParameter1('hello', 10);
|
||||
strOrNum = unionWithRestParameter1('hello', 10, 11);
|
||||
strOrNum = unionWithRestParameter1('hello', "hello"); // error in parameter type
|
||||
~~~~~~~
|
||||
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
||||
strOrNum = unionWithRestParameter1(); // error
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
|
||||
var unionWithRestParameter2: { (a: string, ...b: number[]): string; } | { (a: string, b: number): number };
|
||||
strOrNum = unionWithRestParameter2('hello'); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
strOrNum = unionWithRestParameter2('hello', 10); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
strOrNum = unionWithRestParameter2('hello', 10, 11); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
strOrNum = unionWithRestParameter2('hello', "hello"); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
strOrNum = unionWithRestParameter2(); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
|
||||
var unionWithRestParameter3: { (a: string, ...b: number[]): string; } | { (a: string): number };
|
||||
strOrNum = unionWithRestParameter3('hello'); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
strOrNum = unionWithRestParameter3('hello', 10); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
strOrNum = unionWithRestParameter3('hello', 10, 11); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
strOrNum = unionWithRestParameter3('hello', "hello"); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
strOrNum = unionWithRestParameter3(); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
132
tests/baselines/reference/unionTypeCallSignatures.js
Normal file
132
tests/baselines/reference/unionTypeCallSignatures.js
Normal file
|
@ -0,0 +1,132 @@
|
|||
//// [unionTypeCallSignatures.ts]
|
||||
var numOrDate: number | Date;
|
||||
var strOrBoolean: string | boolean;
|
||||
var strOrNum: string | number;
|
||||
|
||||
// If each type in U has call signatures and the sets of call signatures are identical ignoring return types,
|
||||
// U has the same set of call signatures, but with return types that are unions of the return types of the respective call signatures from each type in U.
|
||||
var unionOfDifferentReturnType: { (a: number): number; } | { (a: number): Date; };
|
||||
numOrDate = unionOfDifferentReturnType(10);
|
||||
strOrBoolean = unionOfDifferentReturnType("hello"); // error
|
||||
unionOfDifferentReturnType1(true); // error in type of parameter
|
||||
|
||||
var unionOfDifferentReturnType1: { (a: number): number; (a: string): string; } | { (a: number): Date; (a: string): boolean; };
|
||||
numOrDate = unionOfDifferentReturnType1(10);
|
||||
strOrBoolean = unionOfDifferentReturnType1("hello");
|
||||
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
|
||||
|
||||
var unionOfDifferentNumberOfSignatures: { (a: number): number; } | { (a: number): Date; (a: string): boolean; };
|
||||
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; } ;
|
||||
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; };
|
||||
strOrNum = unionWithOptionalParameter1('hello');
|
||||
strOrNum = unionWithOptionalParameter1('hello', 10);
|
||||
strOrNum = unionWithOptionalParameter1('hello', "hello"); // error in parameter type
|
||||
strOrNum = unionWithOptionalParameter1(); // error
|
||||
|
||||
var unionWithOptionalParameter2: { (a: string, b?: number): string; } | { (a: string, b: number): number };
|
||||
strOrNum = unionWithOptionalParameter2('hello'); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter2('hello', 10); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter2('hello', "hello"); // error no call signature
|
||||
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', 10); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter3('hello', "hello"); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter3(); // error no call signature
|
||||
|
||||
var unionWithRestParameter1: { (a: string, ...b: number[]): string; } | { (a: string, ...b: number[]): number };
|
||||
strOrNum = unionWithRestParameter1('hello');
|
||||
strOrNum = unionWithRestParameter1('hello', 10);
|
||||
strOrNum = unionWithRestParameter1('hello', 10, 11);
|
||||
strOrNum = unionWithRestParameter1('hello', "hello"); // error in parameter type
|
||||
strOrNum = unionWithRestParameter1(); // error
|
||||
|
||||
var unionWithRestParameter2: { (a: string, ...b: number[]): string; } | { (a: string, b: number): number };
|
||||
strOrNum = unionWithRestParameter2('hello'); // error no call signature
|
||||
strOrNum = unionWithRestParameter2('hello', 10); // error no call signature
|
||||
strOrNum = unionWithRestParameter2('hello', 10, 11); // error no call signature
|
||||
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', 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
|
||||
|
||||
//// [unionTypeCallSignatures.js]
|
||||
var numOrDate;
|
||||
var strOrBoolean;
|
||||
var strOrNum;
|
||||
// If each type in U has call signatures and the sets of call signatures are identical ignoring return types,
|
||||
// U has the same set of call signatures, but with return types that are unions of the return types of the respective call signatures from each type in U.
|
||||
var unionOfDifferentReturnType;
|
||||
numOrDate = unionOfDifferentReturnType(10);
|
||||
strOrBoolean = unionOfDifferentReturnType("hello"); // error
|
||||
unionOfDifferentReturnType1(true); // error in type of parameter
|
||||
var unionOfDifferentReturnType1;
|
||||
numOrDate = unionOfDifferentReturnType1(10);
|
||||
strOrBoolean = unionOfDifferentReturnType1("hello");
|
||||
unionOfDifferentReturnType1(true); // error in type of parameter
|
||||
unionOfDifferentReturnType1(); // error missing parameter
|
||||
var unionOfDifferentParameterTypes;
|
||||
unionOfDifferentParameterTypes(10); // error - no call signatures
|
||||
unionOfDifferentParameterTypes("hello"); // error - no call signatures
|
||||
unionOfDifferentParameterTypes(); // error - no call signatures
|
||||
var unionOfDifferentNumberOfSignatures;
|
||||
unionOfDifferentNumberOfSignatures(); // error - no call signatures
|
||||
unionOfDifferentNumberOfSignatures(10); // error - no call signatures
|
||||
unionOfDifferentNumberOfSignatures("hello"); // error - no call signatures
|
||||
var unionWithDifferentParameterCount;
|
||||
unionWithDifferentParameterCount(); // no call signature
|
||||
unionWithDifferentParameterCount("hello"); // no call signature
|
||||
unionWithDifferentParameterCount("hello", 10); // no call signature
|
||||
var unionWithOptionalParameter1;
|
||||
strOrNum = unionWithOptionalParameter1('hello');
|
||||
strOrNum = unionWithOptionalParameter1('hello', 10);
|
||||
strOrNum = unionWithOptionalParameter1('hello', "hello"); // error in parameter type
|
||||
strOrNum = unionWithOptionalParameter1(); // error
|
||||
var unionWithOptionalParameter2;
|
||||
strOrNum = unionWithOptionalParameter2('hello'); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter2('hello', 10); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter2('hello', "hello"); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter2(); // error no call signature
|
||||
var unionWithOptionalParameter3;
|
||||
strOrNum = unionWithOptionalParameter3('hello'); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter3('hello', 10); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter3('hello', "hello"); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter3(); // error no call signature
|
||||
var unionWithRestParameter1;
|
||||
strOrNum = unionWithRestParameter1('hello');
|
||||
strOrNum = unionWithRestParameter1('hello', 10);
|
||||
strOrNum = unionWithRestParameter1('hello', 10, 11);
|
||||
strOrNum = unionWithRestParameter1('hello', "hello"); // error in parameter type
|
||||
strOrNum = unionWithRestParameter1(); // error
|
||||
var unionWithRestParameter2;
|
||||
strOrNum = unionWithRestParameter2('hello'); // error no call signature
|
||||
strOrNum = unionWithRestParameter2('hello', 10); // error no call signature
|
||||
strOrNum = unionWithRestParameter2('hello', 10, 11); // error no call signature
|
||||
strOrNum = unionWithRestParameter2('hello', "hello"); // error no call signature
|
||||
strOrNum = unionWithRestParameter2(); // error no call signature
|
||||
var unionWithRestParameter3;
|
||||
strOrNum = unionWithRestParameter3('hello'); // error no call signature
|
||||
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
|
|
@ -0,0 +1,70 @@
|
|||
var numOrDate: number | Date;
|
||||
var strOrBoolean: string | boolean;
|
||||
var strOrNum: string | number;
|
||||
|
||||
// If each type in U has call signatures and the sets of call signatures are identical ignoring return types,
|
||||
// U has the same set of call signatures, but with return types that are unions of the return types of the respective call signatures from each type in U.
|
||||
var unionOfDifferentReturnType: { (a: number): number; } | { (a: number): Date; };
|
||||
numOrDate = unionOfDifferentReturnType(10);
|
||||
strOrBoolean = unionOfDifferentReturnType("hello"); // error
|
||||
unionOfDifferentReturnType1(true); // error in type of parameter
|
||||
|
||||
var unionOfDifferentReturnType1: { (a: number): number; (a: string): string; } | { (a: number): Date; (a: string): boolean; };
|
||||
numOrDate = unionOfDifferentReturnType1(10);
|
||||
strOrBoolean = unionOfDifferentReturnType1("hello");
|
||||
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
|
||||
|
||||
var unionOfDifferentNumberOfSignatures: { (a: number): number; } | { (a: number): Date; (a: string): boolean; };
|
||||
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; } ;
|
||||
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; };
|
||||
strOrNum = unionWithOptionalParameter1('hello');
|
||||
strOrNum = unionWithOptionalParameter1('hello', 10);
|
||||
strOrNum = unionWithOptionalParameter1('hello', "hello"); // error in parameter type
|
||||
strOrNum = unionWithOptionalParameter1(); // error
|
||||
|
||||
var unionWithOptionalParameter2: { (a: string, b?: number): string; } | { (a: string, b: number): number };
|
||||
strOrNum = unionWithOptionalParameter2('hello'); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter2('hello', 10); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter2('hello', "hello"); // error no call signature
|
||||
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', 10); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter3('hello', "hello"); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter3(); // error no call signature
|
||||
|
||||
var unionWithRestParameter1: { (a: string, ...b: number[]): string; } | { (a: string, ...b: number[]): number };
|
||||
strOrNum = unionWithRestParameter1('hello');
|
||||
strOrNum = unionWithRestParameter1('hello', 10);
|
||||
strOrNum = unionWithRestParameter1('hello', 10, 11);
|
||||
strOrNum = unionWithRestParameter1('hello', "hello"); // error in parameter type
|
||||
strOrNum = unionWithRestParameter1(); // error
|
||||
|
||||
var unionWithRestParameter2: { (a: string, ...b: number[]): string; } | { (a: string, b: number): number };
|
||||
strOrNum = unionWithRestParameter2('hello'); // error no call signature
|
||||
strOrNum = unionWithRestParameter2('hello', 10); // error no call signature
|
||||
strOrNum = unionWithRestParameter2('hello', 10, 11); // error no call signature
|
||||
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', 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
|
Loading…
Reference in a new issue