我在打字稿中有一个枚举变量,看起来像这样
export enum VoucherType {
DebitVoucher = 1,
CreditVoucher = 2,
PurchaseVoucher = 19
}
登录后
console.log(VoucherType);
输出有问题
{
1: "DebitVoucher",
2: "CreditVoucher",
19: "PurchaseVoucher",
DebitVoucher: 1,
CreditVoucher: 2,
PurchaseVoucher: 19}1:
"DebitVoucher"2:
"CreditVoucher"19:
"PurchaseVoucher"CreditVoucher: 2DebitVoucher: 1PurchaseVoucher: 19: Object
我需要实际的JavaScript对象,如何获得它?预先感谢。
答案 0 :(得分:0)
您需要将枚举属性值定义为字符串。然后它应该起作用。
export enum VoucherType {
DebitVoucher = '1',
CreditVoucher = '2',
PurchaseVoucher = '19'
}
console.log(VoucherType); // output {"DebitVoucher":"1","CreditVoucher":"2","PurchaseVoucher":"19"}