I have set up an actions file containing three different actions:
export const showLoading = createAction(`[application] Show warning notification`);
export const hideLoading = createAction(`[application] Show error notification`);
export const showHttpResponseError = createAction(`[application] Show success notification`, props<{ error: HttpErrorResponse, nextAction: Action }>());
export type Actions = ReturnType<
typeof showLoading |
typeof hideLoading |
typeof showHttpResponseError
>;
Following that, I created an effects file structured as follows:
@Injectable()
export class ApplicationEffects
{
constructor(private actions$: Actions, private dialogsService: DialogsService, public notificationsService: NotificationService, private router: Router) { }
@Effect() public errorHandler$ = this.actions$
.pipe(
ofType(ApplicationActions.showHttpResponseError.type),
switchMap(action => {
const emptyAction = { type: 'noop' };
const error = HttpErrorHandler.handle(action.error);
if (error.redirectTo != null) {
this.router.navigate([error.redirectTo]);
return of(emptyAction);
}
if (action.error.status === 400) {
this.notificationsService.notifyWarning('AVISO', error.messages);
}
else {
this.dialogsService.errorDialog('ERRO', error.messages[0]);
}
return action.nextAction ? of(action.nextAction) : of(emptyAction);
},
));
}
However, I am facing an issue where the VS Code intellisense does not recognize the action type in the switchMap
section and labels it as never
:
https://i.sstatic.net/dgTox.png
Is there something missing from my setup? How can I enforce the correct type for it, especially since the action is generated using ngrx action creators without a specific type definition?