0
{
data: {
user: {
selected: 1502205502995,
entities: {
11: {
actual: {id: 11, name: 'User A changed'},
persist: {id: 11, name: 'User A'},
validationError: {},
serverError: {},
products: {
selected: 1,
entities: {
1: {
actual: {id: 1, description: 'Description of product changed'},
persist: {id: 1, description: 'Description of product '},
deleted: true,
validationError: {},
serverError: {}
},
1502205955851: {
actual: {description: 'Description of product 2'}
}
},
list: {
page: 1,
page_count: 1,
page_size: 20,
total_items: 6,
items: [
{id: 1, description: 'Description of product '},
{id: 1, description: 'Description of product 2'}
]
}
},
notes: {
entities: {}
}
},
23: {
actual: {id: 23, name: 'Karik Guna'},
persist: {id: 23, name: 'Karik Guna'},
validationError: {},
serverError: {}
},
1502205502995: {
actual: {name: 'Karan Gupta'},
validationError: {},
serverError: {},
address: {
entities: {
1502224087221: {
actual: {id: 1502224087221, description: "Description of product"},
validationError: {}
}
}
}
}
},
list: {
page: 1,
page_count: 1,
page_size: 20,
total_items: 8,
items: [
{}
],
loading: false
}
}
}
}
我想擁有這個存儲結構。嵌套對象的Typescript接口
我如何用打字稿界面來描述這一點。
我的意思是有多層次的嵌套對象,每個都可以有一些自定義屬性。
或者也許有一個更好的設計ngrx商店。
API看起來像這樣
api.com/user - 這爲用戶提供了列表
api.com/user/[id]/products - 這給用戶的產品列表
api.com /用戶/ [ID] /產品/ [ID] - 這給用戶具體的產品
我嘗試財產以後這樣
export interface EntityInfo<T1, T2> {
actual: T1 | T2;
persist: T1 | T2;
validation: any;
error: any;
}
export interface State {
selectedId: number | string;
isLoading: boolean;
entities: {
[ id: string ]: {
self: EntityInfo<User, UserResponse>
product: {
selectedId: number | string;
entities: {
[ id: string ]: EntityInfo<Product | ProductResponse>
}
}
}
};
list: {
items: any[]
};
}
這裏我被迫擁有財產性的「自我」父實體
做出的接口是相同的對象?你試過什麼了?你卡在哪裏? – toskv
我會更新問題並添加我試過的東西。 – Varuzhan
請將其添加到問題中,而不是作爲評論。 :) – toskv