本文介绍了TypeError:返回未知类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ngrx/effects .我收到此错误:

I am using ngrx/effects. I got this error:

这是我的代码的一部分:

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

推荐答案

感谢@apreg指出了我在Gitter上的错误.

Thanks for @apreg point out my error on Gitter.

我应该将switchMapTo更改为switchMap.

switchMap switchMapTo .

这篇关于TypeError:返回未知类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 08:15