101 lines
5.5 KiB
Text
101 lines
5.5 KiB
Text
=== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions.ts ===
|
|
// conditional expressions return the best common type of the branches plus contextual type (using the first candidate if multiple BCTs exist)
|
|
// no errors expected here
|
|
|
|
var a: { x: number; y?: number };
|
|
>a : Symbol(a, Decl(bestCommonTypeOfConditionalExpressions.ts, 3, 3))
|
|
>x : Symbol(x, Decl(bestCommonTypeOfConditionalExpressions.ts, 3, 8))
|
|
>y : Symbol(y, Decl(bestCommonTypeOfConditionalExpressions.ts, 3, 19))
|
|
|
|
var b: { x: number; z?: number };
|
|
>b : Symbol(b, Decl(bestCommonTypeOfConditionalExpressions.ts, 4, 3))
|
|
>x : Symbol(x, Decl(bestCommonTypeOfConditionalExpressions.ts, 4, 8))
|
|
>z : Symbol(z, Decl(bestCommonTypeOfConditionalExpressions.ts, 4, 19))
|
|
|
|
class Base { foo: string; }
|
|
>Base : Symbol(Base, Decl(bestCommonTypeOfConditionalExpressions.ts, 4, 33))
|
|
>foo : Symbol(foo, Decl(bestCommonTypeOfConditionalExpressions.ts, 6, 12))
|
|
|
|
class Derived extends Base { bar: string; }
|
|
>Derived : Symbol(Derived, Decl(bestCommonTypeOfConditionalExpressions.ts, 6, 27))
|
|
>Base : Symbol(Base, Decl(bestCommonTypeOfConditionalExpressions.ts, 4, 33))
|
|
>bar : Symbol(bar, Decl(bestCommonTypeOfConditionalExpressions.ts, 7, 28))
|
|
|
|
class Derived2 extends Base { baz: string; }
|
|
>Derived2 : Symbol(Derived2, Decl(bestCommonTypeOfConditionalExpressions.ts, 7, 43))
|
|
>Base : Symbol(Base, Decl(bestCommonTypeOfConditionalExpressions.ts, 4, 33))
|
|
>baz : Symbol(baz, Decl(bestCommonTypeOfConditionalExpressions.ts, 8, 29))
|
|
|
|
var base: Base;
|
|
>base : Symbol(base, Decl(bestCommonTypeOfConditionalExpressions.ts, 9, 3))
|
|
>Base : Symbol(Base, Decl(bestCommonTypeOfConditionalExpressions.ts, 4, 33))
|
|
|
|
var derived: Derived;
|
|
>derived : Symbol(derived, Decl(bestCommonTypeOfConditionalExpressions.ts, 10, 3))
|
|
>Derived : Symbol(Derived, Decl(bestCommonTypeOfConditionalExpressions.ts, 6, 27))
|
|
|
|
var derived2: Derived2;
|
|
>derived2 : Symbol(derived2, Decl(bestCommonTypeOfConditionalExpressions.ts, 11, 3))
|
|
>Derived2 : Symbol(Derived2, Decl(bestCommonTypeOfConditionalExpressions.ts, 7, 43))
|
|
|
|
var r = true ? 1 : 2;
|
|
>r : Symbol(r, Decl(bestCommonTypeOfConditionalExpressions.ts, 13, 3))
|
|
|
|
var r3 = true ? 1 : {};
|
|
>r3 : Symbol(r3, Decl(bestCommonTypeOfConditionalExpressions.ts, 14, 3))
|
|
|
|
var r4 = true ? a : b; // typeof a
|
|
>r4 : Symbol(r4, Decl(bestCommonTypeOfConditionalExpressions.ts, 15, 3))
|
|
>a : Symbol(a, Decl(bestCommonTypeOfConditionalExpressions.ts, 3, 3))
|
|
>b : Symbol(b, Decl(bestCommonTypeOfConditionalExpressions.ts, 4, 3))
|
|
|
|
var r5 = true ? b : a; // typeof b
|
|
>r5 : Symbol(r5, Decl(bestCommonTypeOfConditionalExpressions.ts, 16, 3))
|
|
>b : Symbol(b, Decl(bestCommonTypeOfConditionalExpressions.ts, 4, 3))
|
|
>a : Symbol(a, Decl(bestCommonTypeOfConditionalExpressions.ts, 3, 3))
|
|
|
|
var r6 = true ? (x: number) => { } : (x: Object) => { }; // returns number => void
|
|
>r6 : Symbol(r6, Decl(bestCommonTypeOfConditionalExpressions.ts, 17, 3))
|
|
>x : Symbol(x, Decl(bestCommonTypeOfConditionalExpressions.ts, 17, 17))
|
|
>x : Symbol(x, Decl(bestCommonTypeOfConditionalExpressions.ts, 17, 38))
|
|
>Object : Symbol(Object, Decl(lib.d.ts, 92, 1), Decl(lib.d.ts, 223, 11))
|
|
|
|
var r7: (x: Object) => void = true ? (x: number) => { } : (x: Object) => { };
|
|
>r7 : Symbol(r7, Decl(bestCommonTypeOfConditionalExpressions.ts, 18, 3))
|
|
>x : Symbol(x, Decl(bestCommonTypeOfConditionalExpressions.ts, 18, 9))
|
|
>Object : Symbol(Object, Decl(lib.d.ts, 92, 1), Decl(lib.d.ts, 223, 11))
|
|
>x : Symbol(x, Decl(bestCommonTypeOfConditionalExpressions.ts, 18, 38))
|
|
>x : Symbol(x, Decl(bestCommonTypeOfConditionalExpressions.ts, 18, 59))
|
|
>Object : Symbol(Object, Decl(lib.d.ts, 92, 1), Decl(lib.d.ts, 223, 11))
|
|
|
|
var r8 = true ? (x: Object) => { } : (x: number) => { }; // returns Object => void
|
|
>r8 : Symbol(r8, Decl(bestCommonTypeOfConditionalExpressions.ts, 19, 3))
|
|
>x : Symbol(x, Decl(bestCommonTypeOfConditionalExpressions.ts, 19, 17))
|
|
>Object : Symbol(Object, Decl(lib.d.ts, 92, 1), Decl(lib.d.ts, 223, 11))
|
|
>x : Symbol(x, Decl(bestCommonTypeOfConditionalExpressions.ts, 19, 38))
|
|
|
|
var r10: Base = true ? derived : derived2; // no error since we use the contextual type in BCT
|
|
>r10 : Symbol(r10, Decl(bestCommonTypeOfConditionalExpressions.ts, 20, 3))
|
|
>Base : Symbol(Base, Decl(bestCommonTypeOfConditionalExpressions.ts, 4, 33))
|
|
>derived : Symbol(derived, Decl(bestCommonTypeOfConditionalExpressions.ts, 10, 3))
|
|
>derived2 : Symbol(derived2, Decl(bestCommonTypeOfConditionalExpressions.ts, 11, 3))
|
|
|
|
var r11 = true ? base : derived2;
|
|
>r11 : Symbol(r11, Decl(bestCommonTypeOfConditionalExpressions.ts, 21, 3))
|
|
>base : Symbol(base, Decl(bestCommonTypeOfConditionalExpressions.ts, 9, 3))
|
|
>derived2 : Symbol(derived2, Decl(bestCommonTypeOfConditionalExpressions.ts, 11, 3))
|
|
|
|
function foo5<T, U>(t: T, u: U): Object {
|
|
>foo5 : Symbol(foo5, Decl(bestCommonTypeOfConditionalExpressions.ts, 21, 33))
|
|
>T : Symbol(T, Decl(bestCommonTypeOfConditionalExpressions.ts, 23, 14))
|
|
>U : Symbol(U, Decl(bestCommonTypeOfConditionalExpressions.ts, 23, 16))
|
|
>t : Symbol(t, Decl(bestCommonTypeOfConditionalExpressions.ts, 23, 20))
|
|
>T : Symbol(T, Decl(bestCommonTypeOfConditionalExpressions.ts, 23, 14))
|
|
>u : Symbol(u, Decl(bestCommonTypeOfConditionalExpressions.ts, 23, 25))
|
|
>U : Symbol(U, Decl(bestCommonTypeOfConditionalExpressions.ts, 23, 16))
|
|
>Object : Symbol(Object, Decl(lib.d.ts, 92, 1), Decl(lib.d.ts, 223, 11))
|
|
|
|
return true ? t : u; // BCT is Object
|
|
>t : Symbol(t, Decl(bestCommonTypeOfConditionalExpressions.ts, 23, 20))
|
|
>u : Symbol(u, Decl(bestCommonTypeOfConditionalExpressions.ts, 23, 25))
|
|
}
|