2014-11-04 23:49:15 +01:00
=== tests/cases/conformance/types/union/contextualTypeWithUnionTypeCallSignatures.ts ===
//When used as a contextual type, a union type U has those members that are present in any of
// its constituent types, with types that are unions of the respective members in the constituent types.
// Let S be the set of types in U that have call signatures.
// If S is not empty and the sets of call signatures of the types in S 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 S.
interface IWithNoCallSignatures {
2015-04-16 01:44:20 +02:00
>IWithNoCallSignatures : IWithNoCallSignatures
2014-11-04 23:49:15 +01:00
foo: string;
2015-04-16 01:44:20 +02:00
>foo : string
2014-11-04 23:49:15 +01:00
}
interface IWithCallSignatures {
2015-04-16 01:44:20 +02:00
>IWithCallSignatures : IWithCallSignatures
2014-11-04 23:49:15 +01:00
(a: number): string;
2015-04-16 01:44:20 +02:00
>a : number
2014-11-04 23:49:15 +01:00
}
interface IWithCallSignatures2 {
2015-04-16 01:44:20 +02:00
>IWithCallSignatures2 : IWithCallSignatures2
2014-11-04 23:49:15 +01:00
(a: number): number;
2015-04-16 01:44:20 +02:00
>a : number
2014-11-04 23:49:15 +01:00
}
interface IWithCallSignatures3 {
2015-04-16 01:44:20 +02:00
>IWithCallSignatures3 : IWithCallSignatures3
2014-11-04 23:49:15 +01:00
(b: string): number;
2015-04-16 01:44:20 +02:00
>b : string
2014-11-04 23:49:15 +01:00
}
interface IWithCallSignatures4 {
2015-04-16 01:44:20 +02:00
>IWithCallSignatures4 : IWithCallSignatures4
2014-11-04 23:49:15 +01:00
(a: number): string;
2015-04-16 01:44:20 +02:00
>a : number
2014-11-04 23:49:15 +01:00
(a: string, b: number): number;
2015-04-16 01:44:20 +02:00
>a : string
>b : number
2014-11-04 23:49:15 +01:00
}
// With no call signature | callSignatures
var x: IWithNoCallSignatures | IWithCallSignatures = a => a.toString();
2015-04-16 01:44:20 +02:00
>x : IWithNoCallSignatures | IWithCallSignatures
>IWithNoCallSignatures : IWithNoCallSignatures
>IWithCallSignatures : IWithCallSignatures
2014-11-04 23:49:15 +01:00
>a => a.toString() : (a: number) => string
2015-04-16 01:44:20 +02:00
>a : number
2014-11-04 23:49:15 +01:00
>a.toString() : string
2015-04-16 01:44:20 +02:00
>a.toString : (radix?: number) => string
>a : number
>toString : (radix?: number) => string
2014-11-04 23:49:15 +01:00
// With call signatures with different return type
var x2: IWithCallSignatures | IWithCallSignatures2 = a => a.toString(); // Like iWithCallSignatures
2015-04-16 01:44:20 +02:00
>x2 : IWithCallSignatures | IWithCallSignatures2
>IWithCallSignatures : IWithCallSignatures
>IWithCallSignatures2 : IWithCallSignatures2
2014-11-04 23:49:15 +01:00
>a => a.toString() : (a: number) => string
2015-04-16 01:44:20 +02:00
>a : number
2014-11-04 23:49:15 +01:00
>a.toString() : string
2015-04-16 01:44:20 +02:00
>a.toString : (radix?: number) => string
>a : number
>toString : (radix?: number) => string
2014-11-04 23:49:15 +01:00
var x2: IWithCallSignatures | IWithCallSignatures2 = a => a; // Like iWithCallSignatures2
2015-04-16 01:44:20 +02:00
>x2 : IWithCallSignatures | IWithCallSignatures2
>IWithCallSignatures : IWithCallSignatures
>IWithCallSignatures2 : IWithCallSignatures2
2014-11-04 23:49:15 +01:00
>a => a : (a: number) => number
2015-04-16 01:44:20 +02:00
>a : number
>a : number
2014-11-04 23:49:15 +01:00
// With call signatures of mismatching parameter type
var x3: IWithCallSignatures | IWithCallSignatures3 = a => /*here a should be any*/ a.toString();
2015-04-16 01:44:20 +02:00
>x3 : IWithCallSignatures | IWithCallSignatures3
>IWithCallSignatures : IWithCallSignatures
>IWithCallSignatures3 : IWithCallSignatures3
2014-11-04 23:49:15 +01:00
>a => /*here a should be any*/ a.toString() : (a: any) => any
2015-04-16 01:44:20 +02:00
>a : any
2014-11-04 23:49:15 +01:00
>a.toString() : any
>a.toString : any
2015-04-16 01:44:20 +02:00
>a : any
2014-11-04 23:49:15 +01:00
>toString : any
// With call signature count mismatch
var x4: IWithCallSignatures | IWithCallSignatures4 = a => /*here a should be any*/ a.toString();
2015-04-16 01:44:20 +02:00
>x4 : IWithCallSignatures | IWithCallSignatures4
>IWithCallSignatures : IWithCallSignatures
>IWithCallSignatures4 : IWithCallSignatures4
2014-11-04 23:49:15 +01:00
>a => /*here a should be any*/ a.toString() : (a: any) => any
2015-04-16 01:44:20 +02:00
>a : any
2014-11-04 23:49:15 +01:00
>a.toString() : any
>a.toString : any
2015-04-16 01:44:20 +02:00
>a : any
2014-11-04 23:49:15 +01:00
>toString : any