Ngrx условный swtichMap диспетчеризация нескольких действий - PullRequest
0 голосов
/ 17 января 2019

Webstorm выдает мне ошибку:

TS2345: Аргумент типа (res: any) => Типы свойства 'type' несовместимы. Тип «CLOSE_ACTIVE_CHATS» не может быть назначен типу «DELETE_SELECTED_CHAT».

На моем внутреннем switchMap

switchMap((res) => {//error here
  chat.mdRef.close();
  if (chat.chat.state === 2) {
    return [new CloseOpenChat(chat.chat._id), new 
      DeleteSelectedChat(), 
      new AddClosedChat(chat.chat)];
  })

Полный код

@Effect()
closeChat: Observable<any> = this.actions.pipe(
  ofType(CLOSE_CHAT_CALL),
  map((action: _Actions.AddClosedChat) => {
    return action.payload;
  }),
  switchMap((chat: CloseChatI) => {
    return this.messageService.closeChat(chat.chat._id).pipe(
      // @ts-ignore
      switchMap((res) => {
        chat.mdRef.close();
        if (chat.chat.state === 2) {
          return [new CloseOpenChat(chat.chat._id), new 
            DeleteSelectedChat(), 
            new AddClosedChat(chat.chat)];
        }
        return [new CloseActiveChat(chat.chat._id), new 
          DeleteSelectedChat(), 
          new AddClosedChat(chat.chat)];
      }),
      catchError(ErrorService.handleError)
    );
  }),
  catchError((err) => of(new CallFailed())
  )
);

1 Ответ

0 голосов
/ 17 января 2019

Похоже, DeleteSelectedChat() также отправляет действие, которое приводит к отправке нескольких действий.

Если вы закомментируете DeleteSelectedChat(), вы все еще получаете сообщение об ошибке?

...