Number type narrowing from number|undefined
within arithmetic conditions
#13974
Labels
Working as Intended
The behavior described is the intended behavior; this is not a bug
TypeScript Version: 2.1.5
JavaScript evaluates
undefined > 0
(and other similar constructs) asfalse
and this could be used for type narrowing. Unlike comparisons withnull
,undefined
is rather consistent (https://jsfiddle.net/4u11p7u0/1/).Code
Expected behavior:
the
if (a > 0)
branch narrows the type to number.Actual behavior:
the type of
a
within the branch stays asnumber|undefined
.The text was updated successfully, but these errors were encountered: