Reputation: 1780
I want to get the latest data from the state and make a service call to the backend.I created the below effect for that
onboardGuest$ = createEffect(() => {
return this.actions$.pipe(
ofType(GuestActions.onboardGuest),
withLatestFrom(this.store.select(selectGuest)),
switchMap(([{reqPayload}]) => {
return this.httpClient.post(environment.urls.guestOnboard, reqPayload).pipe(
switchMap(({payload}) => {
return GuestActions.onboardGuestSuccess({resPayload:payload})
}),
catchError((err) => {
return of(GuestActions.onboardGuestFailure({ error: err }))
})
)
})
);
});
but in the second switchMap, I have this error.what am I doing wrong here
Argument of type '({ payload }: Object) => { resPayload: any; } &
TypedAction<"[Guest] Onboard Guest Success">' is not assignable to parameter of type '(value: Object,
index: number) => ObservableInput<any>'.
Type '{ resPayload: any; } & TypedAction<"[Guest] Onboard Guest Success">'
is not assignable to type 'ObservableInput<any>'.
Property '[Symbol.iterator]' is missing in type '{ resPayload: any; } &
TypedAction<"[Guest] Onboard Guest Success">' but required in type 'Iterable<any>'
Upvotes: 1
Views: 1292
Reputation: 12001
here you should use just map
instead of switchMap
because you are just transforming the sync event to sync something, not to observable
map(({payload}) => {
return GuestActions.onboardGuestSuccess({resPayload:payload})
}),
Upvotes: 2