I've tried to implement such a thing and I'm a bit confused. Suppose I need to implement variety of grid based page which designed more or less the same way, but each of them has some peculiarities. That's why I need some base abstract store/query services where I am planning to implement common logic.
Each grid will operate with child of BaseLineItem
:
export interface BaseListItem {
Id: number;
StatusId: number;
// Other properties
}
That the way I try to implement it
export interface PageState<TListItem extends BaseListItem> extends EntityState<TListItem> {
// some state properties
}
export abstract class PageStore<TListItem extends BaseListItem, TState extends PageState<TListItem>> extends EntityStore<TState> {
constructor(initialState: Partial<TState>) {
super(initialState);
}
addNewItems(items: TListItem[]): void {
this.upsertMany(items);
}
}
It's supposed that for each form I will implement children for line item, state and store, so I can have possibilities to add some peculiarities which are specific for each form. But in that place I've faced with a problem in addNewItems
method - upsertMany
, which shows the following error:
Argument of type 'TListItem[]' is not assignable to parameter of type 'getEntityType<TState>[]'.\n Type 'TListItem' is not assignable to type 'getEntityType<TState>'.\n Type 'BaseListItem' is not assignable to type 'getEntityType<TState>'.
It seems that Akita are not able to infer the type for entity.
That is the question. How to solve this problem, without using as any
everywhere(If I start to do it in the very base level, I will lost intellisense across the source code)? I came to the front-end world from the .Net background. Maybe I don't understand something and this architecture pattern isn't the best here? And I need some advice.