-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(catch): fix catch typings #2478
Conversation
returned type is the union of inputs type
Would you mind share examples of |
Would be great to see the use case for this... o.catch((e, c) => c); Which would make |
Any example where you would return an observable with a different type on the catch would reveal the need of union. Take the first example given on docs : Observable.of(1, 2, 3, 4, 5)
.map(n => {
if (n == 4) {
throw 'four!';
}
return n;
})
.catch(err => Observable.of('I', 'II', 'III', 'IV', 'V'))
.subscribe(x => console.log(x));
But I think this apply for all cases because when you use the same type like : obsv$ = Observable.of(1)
.catch( err => Observable.of(0) ); the type of |
@david-driscoll isn't it what exactly happens after a catch ? it's either the source observable or the one defined on catch, you can't know which one and thus can't know for sure the type of emitted item. |
That is actually a fair point, I had forgotten about how that behavior would flow. I have been corrected 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After above comments these changes make sense.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description:
The catch operator is returning an observable with the type of the innerObservable (observable returned when error occur).
It should be a union of the outerObservable's type and the innerObservable's type :