假设我可以访问Keys
类型,该类型定义如下:
type Keys = ('AA' | 'BB' | 'CC')[]
- 如何使用类型
Keys
创建新类型Key
,使此新类型等于:
type Key = 'AA' | 'BB' | 'CC'
请注意,我不能直接指定允许的值(AA
、BB
等(,我只有Keys
类型可供使用。
您可以使用索引类型查询:
type Keys = ('AA' | 'BB' | 'CC')[]
type Key = Keys[number]
游乐场链接