Open
Description
TypeScript Version: 3.9.0-dev.20200222
Search Terms: NaN Truthiness Falsy
Code
function bool(): boolean { return false; }
function number(): number { return NaN; }
let a = number();
let b = bool();
const x = a && b; // type = boolean | 0
console.log(x); // prints NaN (which is neither boolean, nor 0)
Expected behavior:
Type of x
should be number | boolean
.
Since NaN
isn't a "unit type" like 0
, we can't express NaN
without using number
.
Actual behavior:
Type of x
is 0 | boolean
.
Playground Link: playground link
Related Issues:
#32778 (Incorrectly marked as duplicate?)