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