Relates to changes made here
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Prior to v0.16.0 release, it was possible for Epics to return an Observable.empty() from a mergeMap/switchMap when I wanted to emit no actions. This was achievable by passing an empty object to the generic parameter of the Epic interface (AnyAction and NavActions are defined union types in the example below).
export type IEpic = Epic<AnyAction | NavActions | {}, State, EpicDependencies>;
This now errors with property 'type' is missing in {} due to the Epic type constraint.
I could fix this by creating a sentinel action creator that represents a "blank" action, but the Observable.empty() behavior is quite nice in circumstances where I want that behavior. Avoids spamming my redux logs with those actions as well.
I could possibly get behind the argument that swallowing actions in an event dispatching system is sketchy territory, but I have seen the Observable.empty() idiom often in the wild and in examples.
Which versions of redux-observable, and which browser and OS are affected by this issue? Did this work in previous versions of redux-observable?
v0.16.0.
Hmm..That type error seems correct. An empty object does not have a type property. Observable.empty() actually should have a type of Observable<never>, but a fix for that is waiting for v6 of rxjs. You can provide it manually though Observable.empty<never>(). When never is used, you don't need to include it as part of the action union.
So this works and seems correct (lmk if not)
type IEpic = Epic<AnyAction | NavActions, State, EpicDependencies>;
const somethingEpic: IEpic = action$ =>
action$.ofType(SOMETHING)
.mergeMap(() => Observable.empty<never>());
could possibly get behind the argument that swallowing actions in an event dispatching system is sketchy territory, but I have seen the Observable.empty() idiom often in the wild and in examples.
IMO using Observable.empty() in this way is absolutely normal. 馃槃
Providing the never generic parameter made the type errors go away--thanks @jayphelps ! Totally don't mind being explicit about it until we get around to RxJS 6. Feel free to close this issue if you'd like.
Really appreciate the quick response and all the work you've done on redux-observable! I've really enjoyed building with it and have learned a lot about reactive programming in general on the way.
Glad to hear you're enjoying it!
Hi @jayphelps! I am using [email protected] [email protected].
Is there any possibilities to do the same but without typescript?
Because i do like this import { never } from 'rxjs'; then return never() and received:
'Actions must be plain objects.'
Most helpful comment
Hmm..That type error seems correct. An empty object does not have a
typeproperty.Observable.empty()actually should have a type ofObservable<never>, but a fix for that is waiting for v6 of rxjs. You can provide it manually thoughObservable.empty<never>(). Whenneveris used, you don't need to include it as part of the action union.So this works and seems correct (lmk if not)
IMO using
Observable.empty()in this way is absolutely normal. 馃槃