Closed
Description
Consider:
var a: boolean = ...;
var b: boolean = ...;
if (a ^ b) {
// ...
}
Currently attempting to use the ^
operator on boolean
values fails with:
error TS2113: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
The |
and &
bitwise operators have logical counterparts, ||
and &&
. No such ^^
is available.
JavaScript allows bitwise XOR to apply to boolean
values.
Currently workarounds are:
- casting:
<number><any>a ^ <number><any>b
- using a negated equality test:
a !== b
The XOR operator is clearer than both of these.