Within my application, I have identified two distinct categories of RxJS Observable
s:
Observable
s that solely emit data without any errors, allowing me to safely subscribe without specifying an error callback.Observable
s that can emit data as well as errors, requiring both anext
and anerror
callback when subscribing.
The use of Observable.throw()
results in an ErrorObservable
. When a function returns an Observable
falling into the second category, TypeScript unexpectedly anticipates 0 arguments when calling .subscribe()
, even though it should require both next
and error
callbacks. This discrepancy leads me to label type 2 Observable
s as Observable<Foo>
. However, this practice creates uncertainty for subscribers who are unsure if the Observable
might produce an error or not.
How can I effectively differentiate these scenarios? Is there something important that I am overlooking?