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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
=== tests/cases/conformance/controlFlow/controlFlowTruthiness.ts ===
declare function foo(): string | undefined;
>foo : Symbol(foo, Decl(controlFlowTruthiness.ts, 0, 0))
function f1() {
>f1 : Symbol(f1, Decl(controlFlowTruthiness.ts, 0, 43))
let x = foo();
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 3, 7))
>foo : Symbol(foo, Decl(controlFlowTruthiness.ts, 0, 0))
if (x) {
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 3, 7))
x; // string
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 3, 7))
}
else {
x; // string | undefined
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 3, 7))
}
}
function f2() {
>f2 : Symbol(f2, Decl(controlFlowTruthiness.ts, 10, 1))
let x: string | undefined;
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 13, 7))
x = foo();
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 13, 7))
>foo : Symbol(foo, Decl(controlFlowTruthiness.ts, 0, 0))
if (x) {
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 13, 7))
x; // string
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 13, 7))
}
else {
x; // string | undefined
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 13, 7))
}
}
function f3() {
>f3 : Symbol(f3, Decl(controlFlowTruthiness.ts, 21, 1))
let x: string | undefined;
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 24, 7))
if (x = foo()) {
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 24, 7))
>foo : Symbol(foo, Decl(controlFlowTruthiness.ts, 0, 0))
x; // string
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 24, 7))
}
else {
x; // string | undefined
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 24, 7))
}
}
function f4() {
>f4 : Symbol(f4, Decl(controlFlowTruthiness.ts, 31, 1))
let x: string | undefined;
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 34, 7))
if (!(x = foo())) {
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 34, 7))
>foo : Symbol(foo, Decl(controlFlowTruthiness.ts, 0, 0))
x; // string | undefined
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 34, 7))
}
else {
x; // string
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 34, 7))
}
}
function f5() {
>f5 : Symbol(f5, Decl(controlFlowTruthiness.ts, 41, 1))
let x: string | undefined;
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 44, 7))
let y: string | undefined;
>y : Symbol(y, Decl(controlFlowTruthiness.ts, 45, 7))
if (x = y = foo()) {
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 44, 7))
>y : Symbol(y, Decl(controlFlowTruthiness.ts, 45, 7))
>foo : Symbol(foo, Decl(controlFlowTruthiness.ts, 0, 0))
x; // string
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 44, 7))
y; // string | undefined
>y : Symbol(y, Decl(controlFlowTruthiness.ts, 45, 7))
}
else {
x; // string | undefined
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 44, 7))
y; // string | undefined
>y : Symbol(y, Decl(controlFlowTruthiness.ts, 45, 7))
}
}
function f6() {
>f6 : Symbol(f6, Decl(controlFlowTruthiness.ts, 54, 1))
let x: string | undefined;
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 57, 7))
let y: string | undefined;
>y : Symbol(y, Decl(controlFlowTruthiness.ts, 58, 7))
if (x = foo(), y = foo()) {
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 57, 7))
>foo : Symbol(foo, Decl(controlFlowTruthiness.ts, 0, 0))
>y : Symbol(y, Decl(controlFlowTruthiness.ts, 58, 7))
>foo : Symbol(foo, Decl(controlFlowTruthiness.ts, 0, 0))
x; // string | undefined
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 57, 7))
y; // string
>y : Symbol(y, Decl(controlFlowTruthiness.ts, 58, 7))
}
else {
x; // string | undefined
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 57, 7))
y; // string | undefined
>y : Symbol(y, Decl(controlFlowTruthiness.ts, 58, 7))
}
}
function f7(x: {}) {
>f7 : Symbol(f7, Decl(controlFlowTruthiness.ts, 67, 1))
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 69, 12))
if (x) {
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 69, 12))
x; // {}
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 69, 12))
}
else {
x; // {}
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 69, 12))
}
}
function f8<T>(x: T) {
>f8 : Symbol(f8, Decl(controlFlowTruthiness.ts, 76, 1))
>T : Symbol(T, Decl(controlFlowTruthiness.ts, 78, 12))
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 78, 15))
>T : Symbol(T, Decl(controlFlowTruthiness.ts, 78, 12))
if (x) {
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 78, 15))
x; // {}
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 78, 15))
}
else {
x; // {}
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 78, 15))
}
}
function f9<T extends object>(x: T) {
>f9 : Symbol(f9, Decl(controlFlowTruthiness.ts, 85, 1))
>T : Symbol(T, Decl(controlFlowTruthiness.ts, 87, 12))
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 87, 30))
>T : Symbol(T, Decl(controlFlowTruthiness.ts, 87, 12))
if (x) {
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 87, 30))
x; // {}
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 87, 30))
}
else {
x; // never
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 87, 30))
}
}
|