具有数值的JavaScript嵌套枚举
目前,枚举的形状正常:
export enum CountryIndex {
JAPAN = 0,
CHINA = 1,
INDIA = 2
}
我需要在其中添加一个类别,例如大陆,以便看起来像这样:
export enum CountryIndex {
ASIA: { JAPAN = 0,
CHINA = 1,
INDIA = 2
},
EUROPE: { SPAIN = 0,
ITALY = 1
}
}
上面的类别是不正确的,是否有一种方法可以使具有数值值的嵌套枚举?
Currently the enum has this shape which works fine:
export enum CountryIndex {
JAPAN = 0,
CHINA = 1,
INDIA = 2
}
I need to add a category inside of it, for example continents, in order to look like this:
export enum CountryIndex {
ASIA: { JAPAN = 0,
CHINA = 1,
INDIA = 2
},
EUROPE: { SPAIN = 0,
ITALY = 1
}
}
The above one is not correct, is there a way to make a nested enum with numerical values?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
枚举值的基础类型必须是字符串或数字。
您最接近的是使用对象。类似的东西
The underlying types for an enum values need to be either strings or numbers.
Your closest thing would be to use objects. Something similar to this