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
constnil=null;// Compile error:// "Operator '<' cannot be applied to types 'null' and 'number'"if(nil<10){}// Use function to trick the type narrowingfunctiontest(): number|null{returnnull;}constn=test();// OKif(n<1){}
Expected behavior:
Both comparisons should generate a compilation error.
Actual behavior:
The first comparison (nil < 10) fails to compile (as expected), but the second one (n < 1) compiles successfully.
It seems odd that the same operation (less-than number) is not allowed for null (what is completely fine), but allowed for union type that includesnull. If there are some solid reasons to behave this way, I think they should be mentioned in the language guide (can't find something about it).