我有枚举:
export enum 算法rithmEnum {
SHA1,
SHA256,
SHA512
}
我将其用于一个类的属性算法:
export class Authenticator {
Type: Type = Type.TOTP;
Icon: string = '';
Issuer: string = '';
Username: string = '';
Secret: string = '';
Pin: null = null;
算法rithm: 算法rithmEnum = 算法rithmEnum.SHA1;
Digits: number = 6;
Period: number = 30;
Counter: number = 0;
CopyCount: number = 0;
Ranking: number = 0;
constructor() {
}
}
然后,在其中一个组件中,我try 将其与switch 一起使用:
exportUriList() {
const authData = this.authDataService.authData;
let uriList: string[] = [];
authData.Authenticators.forEach(auth => {
//otpauth://totp/IBM%20Security%20Verify:@USER_NAME@?secret=@SECRET_KEY@&issuer=IBM%20Security%20Verify&algorithm=@ALGORITHM@
let issuerAndUsername = `${auth.Issuer}:${auth.Username}`;
let secret = `?secret=${auth.Secret}`;
let issuer = `&issuer=${auth.Issuer}`;
let algorithm = '';
if (auth.算法rithm) {
switch (auth.算法rithm) {
case 算法rithmEnum.SHA1:
break;
case 算法rithmEnum.SHA256:
break;
case 算法rithmEnum.SHA512:
break;
}
algorithm = `&algorithm=${auth.算法rithm}`;
}
let uri = 'otpauth://totp/';
});
}
Seems like should work, right? It doesn't: Why I get this error? It looks like typescript missed one of the enums and there is no proper type?
Type '算法rithmEnum.SHA1' is not comparable to type '算法rithmEnum.SHA256 | 算法rithmEnum.SHA512'.