Skip to content

Allow logical XOR using ^ operator #587

Closed
@drewnoakes

Description

@drewnoakes

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions