nullthrows has either bad condition or bad error message
Closed this issue · 1 comments
Hi, while debugging DraftJS, I found out that the function nullthrows
checks only for null
, but its error message says "Got unexpected null or undefined"
Also, the way its result is typed seems wrong, because undefined
passes the condition returning undefined
where non-nullable T
should be ...
I would expect it to either check also for undefined
, or return T | undefined
and not return undefined
in the error message ...
I found out that the function nullthrows checks only for null
That's not correct, the function does a != null
check which means that null
and undefined
are both considered not equal to null
. If the function instead used !== null
then you would be correct.
i just double-checked in the JS console in Chrome to be sure:
null != null
false
undefined != null
false
0 != null
true
I suspect the problem is somewhere else.