In Typescript I can do this:
var xxx : some_type;
if (xxx)
foo();
else
bar();
Here xxx will be treated as a boolean, regardless of its
While you can't cast a number directly to a boolean, you can cast it to the wrapper Boolean class and immediately unwrap it. For example:
foo(xxx);
While clumsy, it avoids the type erasure of casting to
. It's also arguably less obscure & more readable than the !!
approach (certainly so in the transpiled js code).