2016-06-26 193 views
0

我正在使用ngrx/effects。我得到这个错误:类型错误:未知类型返回

ORIGINAL EXCEPTION: TypeError: unknown type returned

这是我的代码部分:

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' }); 
    } 

什么可能导致此?谢谢

回答

0

感谢@apreg指出我在Gitter上的错误。我应该将switchMapTo更改为switchMap

switchMapswitchMapTo的官方文档和解释。

+1

就这样;) – apreg