Closed
Description
TypeScript Version:
1.8.10
Code
// A self-contained demonstration of the problem follows...
function bool_fun(value: string) : boolean {
return value && value == "bug";
}
console.log(bool_fun(null)); // should log false or throw a compiler error, but logs null
console.log(bool_fun("false"));
console.log(bool_fun("bug"));
A boolean
value should always be true
or false
, but never null
(even if it's a falsy value). This would break strict comparisons like ===
. The spec is also very clear: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#3.2.2
Expected behavior:
Either we have a compiler error or the console prints:
false
false
true
Actual behavior:
The console prints:
null
false
true