[英]Typescript Union Array using String Enum for Key Names
有沒有辦法簡化這個聲明:
Array<{ [enum.example1]: Example } | { [enum.example2]: Example } | ...>
// or equivalent
({ [enum.example1]: Example } | { [enum.example2]: Example } | ...)[];
所以它更像{ [key: string]: Example }
,但使用字符串枚舉來限制可能的鍵:
例如,這些似乎不起作用:
{ [enum]: Example }[];
// or
{ [key: enum]: Example }[];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.