-
Notifications
You must be signed in to change notification settings - Fork 12.8k
/
Copy pathbestCommonTypeOfConditionalExpressions2.types
95 lines (81 loc) · 1.72 KB
/
bestCommonTypeOfConditionalExpressions2.types
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
=== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts ===
// conditional expressions return the best common type of the branches plus contextual type (using the first candidate if multiple BCTs exist)
// these are errors
class Base { foo: string; }
>Base : Base
>foo : string
class Derived extends Base { bar: string; }
>Derived : Derived
>Base : Base
>bar : string
class Derived2 extends Base { baz: string; }
>Derived2 : Derived2
>Base : Base
>baz : string
var base: Base;
>base : Base
>Base : Base
var derived: Derived;
>derived : Derived
>Derived : Derived
var derived2: Derived2;
>derived2 : Derived2
>Derived2 : Derived2
var r2 = true ? 1 : '';
>r2 : string | number
>true ? 1 : '' : 1 | ""
>true : true
>1 : 1
>'' : ""
var r9 = true ? derived : derived2;
>r9 : Derived | Derived2
>true ? derived : derived2 : Derived | Derived2
>true : true
>derived : Derived
>derived2 : Derived2
function foo<T, U>(t: T, u: U) {
>foo : <T, U>(t: T, u: U) => T | U
>T : T
>U : U
>t : T
>T : T
>u : U
>U : U
return true ? t : u;
>true ? t : u : T | U
>true : true
>t : T
>u : U
}
function foo2<T extends U, U>(t: T, u: U) { // Error for referencing own type parameter
>foo2 : <T extends U, U>(t: T, u: U) => U
>T : T
>U : U
>U : U
>t : T
>T : T
>u : U
>U : U
return true ? t : u; // Ok because BCT(T, U) = U
>true ? t : u : U
>true : true
>t : T
>u : U
}
function foo3<T extends U, U extends V, V>(t: T, u: U) {
>foo3 : <T extends U, U extends V, V>(t: T, u: U) => U
>T : T
>U : U
>U : U
>V : V
>V : V
>t : T
>T : T
>u : U
>U : U
return true ? t : u;
>true ? t : u : U
>true : true
>t : T
>u : U
}