0
所以我有這個數據結構在打字稿,你怎麼了,你鍵入特定的鍵對象常量
export interface StoreData {
msdb: {[tableName: string]: List<StoreModel>};
}
,但我想只允許(並獲得IntelliSence)對我的表名特定字符串的值。 所以,我試圖像下面,但它沒有工作:
var tableNames:'table_campaigns' | 'table_resources'
export interface StoreData {
msdb: {[tableName]: List<StoreModel>};
}
也試過,沒有運氣
interface IMyTables {
'table_campaigns: string
'table_resources: string;
}
type MyTables = keyof IMyTables;
export interface StoreData {
participants: { [key: number]: any };
threads: { [key: number]: any };
messages: { [key: number]: any };
msdb: {MyTables: List<StoreModel>};
}
也試過
type allMyTables = 'table_campaigns' | 'table_resources'
export interface StoreData {
msdb: {[tableName: allMyTables]: List<StoreModel>};
}
Thanks for reading,
Sean
也許我誤解了g但爲什麼不添加顯式屬性而不是索引? 'msdb:{[tableName:string]:List,table_campaigns:List ,table_resources:List };'。 –