While working with ngrx/effects, I encountered an error:
ERROR: TypeError: unexpected type returned
Here's an excerpt of my code:
this.store.dispatch({ type: CHAT_LOAD_MESSAGES, payload: chatId });
@Effect() loadMessages$ = this.updates$
.whenAction(CHAT_LOAD_MESSAGES)
.map<string>(toPayload)
.do(chatId => console.log('chatId', chatId)) // Able to successfully retrieve chatId here
.switchMapTo(chatId => this.chatService.loadMessages(chatId)) // The error occurred in this line
.do(res => console.log('res', res)) // This part did not execute
.map((messages: Message[]) => ({ type: CHAT_LOAD_MESSAGES_SUCCESS, payload: messages }));
loadMessages(chatId: string): Observable<Message[]> {
// Currently testing with this approach.
// Is there a mistake in this line? How do I simulate it correctly?
return Observable.of([{ id:1, content:'Hi' });
}
Any insights on what might be causing this issue? Thank you