【发布时间】:2019-11-26 18:35:03
【问题描述】:
我有一个联合类型:
type Browser = 'chrome' | 'firefox'
我想创建一个接口/类型,其中有效属性只能是 chrome 和 firefox。我想出了这个:
type IM {
[key in Browser]: {
string: boolean
}
}
问题是我希望允许 chrome 和 firefox 属性中的任何属性。可能吗?我试图使用括号概念:
[string]: boolean
但不出所料,它不起作用。
【问题讨论】:
-
类型浏览器 = 'chrome' | '火狐' |字符串;
标签: typescript types interface