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 type.
I would like to do the same thing in a function argument. I have this function:
function foo(b : boolean) { ... }
I want to be able to call foo(xxx)
and have xxx treated as a boolean, regardless of its type. But Typescript won't allow that.
I tried this:
foo(<boolean>xxx);
but that Typescript won't allow that either.
I can do this:
foo(xxx ? true : false);
But that seems a bit silly. Is there a better way to do it?
if (xxx)
, there is little reason that I shouldn't be able to use a non-boolean in other boolean contexts. In my opinion, it should either allow both or prohibit both.!!
works because the input of the not operator is Any and the output is Boolean.