0
votes

Webstorm is giving me an error:

TS2345: Argument of type (res: any) => Types of property 'type' are incompatible. Type '"CLOSE_ACTIVE_CHATS"' is not assignable to type '"DELETE_SELECTED_CHAT"'.

On my inner 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)];
  })

Full code

@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
The error you are getting is from the TypeScript compiler, not Webstorm - and it's probably a valid type error. Could you put up a Stackblitz with all your @ngrx code so I can have a look?hevans900
thanks for the formating, its my first post here. Its a project for work with about 5000 lines,I dont think i am allowed to post it. When I make @ts-ignore, it works fine. Its easy to reproduce though: when a switchMap conditionally returns actions, it gives this errorJensen

1 Answers

0
votes

It looks like DeleteSelectedChat() also dispatches an action, which leads to multiple actions dispatched.

If you comment out DeleteSelectedChat() do you still get the error?