TypeScript/tests/cases/conformance/controlFlow/controlFlowTruthiness.ts
Anders Hejlsberg d2b89be4bc Adding test
2016-04-21 13:03:08 -07:00

71 lines
1.2 KiB
TypeScript

// @strictNullChecks: true
declare function foo(): string | undefined;
function f1() {
let x = foo();
if (x) {
x; // string
}
else {
x; // string | undefined
}
}
function f2() {
let x: string | undefined;
x = foo();
if (x) {
x; // string
}
else {
x; // string | undefined
}
}
function f3() {
let x: string | undefined;
if (x = foo()) {
x; // string
}
else {
x; // string | undefined
}
}
function f4() {
let x: string | undefined;
if (!(x = foo())) {
x; // string | undefined
}
else {
x; // string
}
}
function f5() {
let x: string | undefined;
let y: string | undefined;
if (x = y = foo()) {
x; // string
y; // string | undefined
}
else {
x; // string | undefined
y; // string | undefined
}
}
function f6() {
let x: string | undefined;
let y: string | undefined;
if (x = foo(), y = foo()) {
x; // string | undefined
y; // string
}
else {
x; // string | undefined
y; // string | undefined
}
}