问题
I am using ngrx/effects. I got this error:
ORIGINAL EXCEPTION: TypeError: unknown type returned
This is part of my codes:
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)) // Here I can get chatId
.switchMapTo(chatId => this.chatService.loadMessages(chatId)) // The error comes out because of this line
.do(res => console.log('res', res)) // This didn't run
.map((messages: Message[]) => ({ type: CHAT_LOAD_MESSAGES_SUCCESS, payload: messages }));
loadMessages(chatId: string): Observable<Message[]> {
// This is what I am using to test right now.
// Maybe this line is wrong? How can I write correct simulation?
return Observable.of([{ id:1, content:'Hi' });
}
What may cause this? Thanks
回答1:
Thanks for @apreg point out my error on Gitter.
I should change switchMapTo
to switchMap
.
The official document and explanation of switchMap and switchMapTo.
来源:https://stackoverflow.com/questions/38035214/typeerror-unknown-type-returned