You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JavaScript evaluates undefined > 0 (and other similar constructs) as false and this could be used for type narrowing. Unlike comparisons with null, undefined is rather consistent (https://jsfiddle.net/4u11p7u0/1/).
Code
leta: number|undefined;functionexpectNumber(a: number){}if(a!=null){// worksexpectNumber(a);}if(a>0){// does not work but should because "undefined > 0 === false"expectNumber(a);}
Expected behavior:
the if (a > 0) branch narrows the type to number.
Actual behavior:
the type of a within the branch stays as number|undefined.