-
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
Pipe operator cannot infer return type as ConnectableObservable #2972
Comments
The problem can be solved by adding additional overload signatures to For example: pipe<A>(op1: UnaryFunction<Observable<T>, ConnectableObservable<A>>): ConnectableObservable<A>;
pipe<A>(op1: OperatorFunction<T, A>): Observable<A>; Using An import of The signatures for Interestingly, adding such overload signatures to const o = of(0).pipe(publishReplay(1)); is inferred as |
Actually, if the overload signatures for pipe<A, OA extends Observable<A>>(op1: UnaryFunction<Observable<T>, OA>): OA;
pipe<A, B, OB extends Observable<B>>(op1: OperatorFunction<T, A>, op2: UnaryFunction<Observable<A>, OB>): OB;
// etc. The problem can be solved without specific reference to This seems to be okay with the version of TypeScript (2.0) that RxJS uses, but I've not investigated this thoroughly. |
This issue still exists in rxjs 6.0 final. Reproduce: const connectableObservable = from([1, 2, 3]).pipe(publish());
connectableObservable.connect()
Edit: Used latest typescript 2.8.3. |
Yeah still the issue exists .. Thanks for pointing me to the original issue. |
Allows specific types of Observables to be passed through (as in ReactiveX#2972), and also prevents incorrect typings from falling through to ellipsis function due to the use of `any`.
Allows specific types of Observables to be passed through (as in ReactiveX#2972), and also prevents incorrect typings from falling through to ellipsis function due to the use of `any`.
Allows specific types of Observables to be passed through (as in ReactiveX#2972), and also prevents incorrect typings from falling through to ellipsis function due to the use of `any`.
Allows specific types of Observables to be passed through (as in ReactiveX#2972), and also prevents incorrect typings from falling through to ellipsis function due to the use of `any`. Closes ReactiveX#2972
https://www.learnrxjs.io/operators/multicasting/publish.html did not work for me until doing this. |
I just ran into this issue while updating from rxjs 5.5.6 to 6.3.2. I see it has been a while since any activity here. Should we expect any fix in the future? The code I was updating was using publish and then connect, which I updated to have the publish inside a pipe like in the example from @Dynalon. I also got a Observable type instead of a ConnectableObservable, so the connect call got a type error. |
Workaround:
EDIT: that's wrong, it will just type the connectable (see @simeyla comment below) |
@ebrehault this looks like (type)safer workaround upd: actually that can be wrapped into observable factory function to provide better type inference and more traditional shape:
upd:
@benlesh @cartant what do you say, is it possible to fix with the whole |
@fljot In v7 it won't be an issue, as the operators that will be pipeable won't return a |
I got myself super confused by this whole issue, so just wanted to add a couple findings that may help others - especially in understanding what is not the problem:
In other words the type of When @fljot's answer is most useful to solve this problem because all it does it to call the So you can publish a stream, use it to create other streams and then The only recommendation I have for usage is to call it on a separate line like this:
@ebrehault your answer is misleading. The
|
@simeyla oh right! true! thanks :) |
@simeyla Why do you claim It does: https://github.com/ReactiveX/rxjs/blob/6.5.2/src/internal/operators/publishReplay.ts#L24 |
I'm curious if this is considered a bug that's going to get fixed? I am fine type casting but would prefer not to. |
still an issue???? |
Piping the type of ConnectableObservable is currently planned to be removed in v.8: #5431 |
Closing this 'cause |
RxJS version: 5.5.0
Code to reproduce:
Expected behavior: The inferred type of
connectableObs
isConnectableObservable<number>
.Actual behavior: The inferred type of
connectableObs
isObservable<number>
.Additional information:
TypeScript version: 2.5.3
My current workaround is to manually downcast the return value:
Happy to send a PR, but not sure how should I fix this properly.
The text was updated successfully, but these errors were encountered: