我有以下界面
interface Details {
id: string;
groups: Group[];
name: string;
total: number;
open: boolean;
debug: boolean;
demo: boolean;
registered: boolean;
}
然后,我希望一個型別是該型別中任何屬性名稱的陣列Details
。
例如['total', 'open', 'demo']
將是有效的。
我試過了
type RequiredFields = { [key in Details]?: string };
但我收到以下 TypeScript 錯誤。
Type 'Details' is not assignable to type 'string | number | symbol'.
Type 'Details' is not assignable to type 'symbol'.
任何幫助將不勝感激。
uj5u.com熱心網友回復:
您正在尋找的可能是:
type RequiredFields = (keyof Details)[];
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/529950.html
標籤:打字稿