TypeError: unknown type returned

a 夏天 提交于 2020-01-07 01:55:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!