typescript - TypeScript:在复杂类型中组合枚举
问题描述
我在 TypeScript 3.7.5 中有两个enum
s 和 a const
,我想用enum
s 来写一个相当复杂type
的常量
enum Action {
Jump,
Run,
Shoot,
}
enum Character {
Foo,
Bar,
}
type IDontKnow = ...;
const actions: IDontKnow = {
[Character.Foo]: {
[Action.Jump]: false,
[Action.Run]: true,
[Action.Shoot]: false,
},
[Character.Bar]: {
[Action.Jump]: false,
[Action.Run]: true,
[Action.Shoot]: true,
},
};
enum
问题是我通常在使用s 或不知道对象将有多少键时使用方括号来表示类型,但我认为我不能同时使用这两个键:
const usingEnums: { [Character]: string; } = {
[Character.Foo]: 'John'
};
const usingArray: { [name: string]: Action[] } = {
'John': [Action.Run, Action.Shoot],
'Jane': [Action.Jump, Action.Run, Action.Shoot]
};
有什么想法吗?
解决方案
推荐阅读
- python - 如何使“pygame.event.get()”在 pygame 的所有模块中可用
- datetime - chrono::format::strftime 不适用于 UNIX 时间戳
- c# - WebView2 控件未加载 HTML 字符串
- javascript - 如何在javascript中的数组中放置特殊字符
- python - 我应该如何处理 Pycharm 代码建议?
- python - 具有显式调用的字符串的真值和假值
- python - 检测图像上的对象边界太慢
- visual-studio-code - VSCode 文件夹不按字母顺序排序
- java - 如何使用 REST Assured 发送带有格式错误的查询参数或 URL 中的路径的请求?
- javascript - HTML表格一分为二,并排显示在同一页面上