-
Notifications
You must be signed in to change notification settings - Fork 13k
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
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?)
reubenrybnik, improbable-nickkrempel, paul-marechal and Roger322
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript