86 lines
5.2 KiB
Text
86 lines
5.2 KiB
Text
=== 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 {
|
|
>IWithNoCallSignatures : Symbol(IWithNoCallSignatures, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 0, 0))
|
|
|
|
foo: string;
|
|
>foo : Symbol(foo, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 7, 33))
|
|
}
|
|
interface IWithCallSignatures {
|
|
>IWithCallSignatures : Symbol(IWithCallSignatures, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 9, 1))
|
|
|
|
(a: number): string;
|
|
>a : Symbol(a, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 11, 5))
|
|
}
|
|
interface IWithCallSignatures2 {
|
|
>IWithCallSignatures2 : Symbol(IWithCallSignatures2, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 12, 1))
|
|
|
|
(a: number): number;
|
|
>a : Symbol(a, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 14, 5))
|
|
}
|
|
interface IWithCallSignatures3 {
|
|
>IWithCallSignatures3 : Symbol(IWithCallSignatures3, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 15, 1))
|
|
|
|
(b: string): number;
|
|
>b : Symbol(b, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 17, 5))
|
|
}
|
|
interface IWithCallSignatures4 {
|
|
>IWithCallSignatures4 : Symbol(IWithCallSignatures4, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 18, 1))
|
|
|
|
(a: number): string;
|
|
>a : Symbol(a, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 20, 5))
|
|
|
|
(a: string, b: number): number;
|
|
>a : Symbol(a, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 21, 5))
|
|
>b : Symbol(b, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 21, 15))
|
|
}
|
|
|
|
// With no call signature | callSignatures
|
|
var x: IWithNoCallSignatures | IWithCallSignatures = a => a.toString();
|
|
>x : Symbol(x, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 25, 3))
|
|
>IWithNoCallSignatures : Symbol(IWithNoCallSignatures, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 0, 0))
|
|
>IWithCallSignatures : Symbol(IWithCallSignatures, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 9, 1))
|
|
>a : Symbol(a, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 25, 52))
|
|
>a.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
|
>a : Symbol(a, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 25, 52))
|
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
|
|
|
// With call signatures with different return type
|
|
var x2: IWithCallSignatures | IWithCallSignatures2 = a => a.toString(); // Like iWithCallSignatures
|
|
>x2 : Symbol(x2, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 28, 3), Decl(contextualTypeWithUnionTypeCallSignatures.ts, 29, 3))
|
|
>IWithCallSignatures : Symbol(IWithCallSignatures, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 9, 1))
|
|
>IWithCallSignatures2 : Symbol(IWithCallSignatures2, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 12, 1))
|
|
>a : Symbol(a, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 28, 52))
|
|
>a.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
|
>a : Symbol(a, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 28, 52))
|
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
|
|
|
var x2: IWithCallSignatures | IWithCallSignatures2 = a => a; // Like iWithCallSignatures2
|
|
>x2 : Symbol(x2, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 28, 3), Decl(contextualTypeWithUnionTypeCallSignatures.ts, 29, 3))
|
|
>IWithCallSignatures : Symbol(IWithCallSignatures, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 9, 1))
|
|
>IWithCallSignatures2 : Symbol(IWithCallSignatures2, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 12, 1))
|
|
>a : Symbol(a, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 29, 52))
|
|
>a : Symbol(a, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 29, 52))
|
|
|
|
// With call signatures of mismatching parameter type
|
|
var x3: IWithCallSignatures | IWithCallSignatures3 = a => /*here a should be any*/ a.toString();
|
|
>x3 : Symbol(x3, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 32, 3))
|
|
>IWithCallSignatures : Symbol(IWithCallSignatures, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 9, 1))
|
|
>IWithCallSignatures3 : Symbol(IWithCallSignatures3, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 15, 1))
|
|
>a : Symbol(a, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 32, 52))
|
|
>a : Symbol(a, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 32, 52))
|
|
|
|
// With call signature count mismatch
|
|
var x4: IWithCallSignatures | IWithCallSignatures4 = a => /*here a should be any*/ a.toString();
|
|
>x4 : Symbol(x4, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 35, 3))
|
|
>IWithCallSignatures : Symbol(IWithCallSignatures, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 9, 1))
|
|
>IWithCallSignatures4 : Symbol(IWithCallSignatures4, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 18, 1))
|
|
>a : Symbol(a, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 35, 52))
|
|
>a : Symbol(a, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 35, 52))
|
|
|