Khushi Sharma Khushi Sharma - 1 year ago 84
TypeScript Question

Type 'Observable<{}>' is not assignable to type 'Observable<Item[]>: Rxjs




export const items = (state: any = [], {type, payload}) => {
switch (type) {
return state;

export interface Item {
id: number;
name: string;
description: string;

export interface AppStore {
items: Item[];
selectedItem: Item;

export class ListService {
items: Observable<Array<Item>>;
private listModel: ItemList = new ItemList();

constructor(private itemListApi: ItemListApi, private store: Store<AppStore>) {
this.items ='items');===>Error


I'm getting an error in
. The error is "Type 'Observable<{}>' is not assignable to type 'Observable". What went wrong? Any help on this?

Answer Source

This happens because you defined items as Observable<Array<Item>> while'items') probably returns Observable<T>.

You can use type casting to tell the compiler what you're expecting it to return:

this.items = <Observable<Item[]>>'items');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download