Currently, I have implemented a combination of while and switch-case loops to handle various enum values within the constants.Sides
enum.
// NOTE: The Constants import statement is located at the top of the file.
import * as constants from '../constants'
// ... additional code omitted
let crossedSide: constants.Sides | undefined;
let loopGuard = 0;
while ((crossedSide = this.hasCrossedBorder()) && loopGuard < 2) {
loopGuard += 1;
switch (crossedSide) {
case constants.Sides.TOP: { // ISSUE OCCURS HERE
this.velocity.y = -this.velocity.y;
break;
}
case constants.Sides.RIGHT: {
this.velocity.x = -this.velocity.x;
break;
}
case constants.Sides.BOTTOM: {
this.velocity.y = -this.velocity.y;
break;
}
case constants.Sides.LEFT: {
this.velocity.x = -this.velocity.x;
break;
}
default:
break;
}
}
The enum itself is defined in constants/index.ts
with the following structure:
export enum Sides {
TOP,
RIGHT,
BOTTOM,
LEFT,
}
However, an error occurs specifically when accessing the constants.Sides.TOP
case in the switch statement:
Type 'Sides.TOP' is not comparable to type 'Sides.RIGHT | Sides.BOTTOM | Sides.LEFT'.