Within my codebase, I have defined an enum called AlgorithmEnum:
export enum AlgorithmEnum {
SHA1,
SHA256,
SHA512
}
This enum is utilized as the Algorithm property of a class named Authenticator:
export class Authenticator {
Type: Type = Type.TOTP;
Icon: string = '';
Issuer: string = '';
Username: string = '';
Secret: string = '';
Pin: null = null;
Algorithm: AlgorithmEnum = AlgorithmEnum.SHA1;
// Additional properties omitted for brevity
constructor() {
}
}
However, when attempting to apply a switch statement with this enum in one of the components, an error is encountered:
exportUriList() {
const authData = this.authDataService.authData;
let uriList: string[] = [];
authData.Authenticators.forEach(auth => {
let issuerAndUsername = `${auth.Issuer}:${auth.Username}`;
let secret = `?secret=${auth.Secret}`;
let issuer = `&issuer=${auth.Issuer}`;
let algorithm = '';
if (auth.Algorithm) {
switch (auth.Algorithm) {
case AlgorithmEnum.SHA1:
break;
case AlgorithmEnum.SHA256:
break;
case AlgorithmEnum.SHA512:
break;
}
algorithm = `&algorithm=${auth.Algorithm}`;
}
let uri = 'otpauth://totp/';
});
}
The error message suggests a comparison issue between the enums:
Type 'AlgorithmEnum.SHA1' is not comparable to type 'AlgorithmEnum.SHA256 | AlgorithmEnum.SHA512'.