Reputation: 502
I have an ionic 4 application where I am using NgRX 8.
The following code compiles:
connect1$ =
this.actions$.pipe(
// restart counter on every click
switchMap(() => interval(1000))
);
but when I use createEffect() as follows:
connect2$ = createEffect(() =>
this.actions$.pipe(
// restart counter on every click
switchMap(() => interval(1000))
)
);
I get the following error:
Type 'Observable' is not assignable to type 'Observable | ((...args: any[]) => Observable)'
I saw in a previous post the suggestion of removing createEffect() to get to the issue with the syntax. But when I do this the older syntax does not give any issues.
NgRX 8 effects - Type 'Observable<unknown>' is not assignable to type 'Observable<Action>'
Any suggestions as to what I might look at?
Thanks
Upvotes: 2
Views: 1911
Reputation: 8002
TL;DR: Are you looking for ActionsSubject
?
Your effect doesn't seem to do anything (even if it had a { dispatch: false }
).
I find it helpful to think in terms of the following diagram.
In my mind effects should either be
This forces you to think in the following fashion:
This leads to creation of appropriate actions for each.
If you want to have state change than use appropriate actions (say RESTART_TIMER which in the reducer updates state with the time of last reset) and use selector to create the counter but you may be better off doing this in the component with a ActionsSubject
subscription similar to this question
Upvotes: 0
Reputation: 15487
The older syntax, does not have type checking - the new one does and hence this error. Now you get an error at compile time instead of an unexpected error at runtime.
You're getting this error because an effect should always return an Action
, unless specified with { dispatch: false }
Upvotes: 2