Pipe operator cannot infer return type as ConnectableObservable
See original GitHub issueRxJS version: 5.5.0
Code to reproduce:
const obs = Observable.of(5);
const connectableObs = obs.pipe(
publishReplay(1)
);
Expected behavior: The inferred type of connectableObs
is ConnectableObservable<number>
.
Actual behavior: The inferred type of connectableObs
is Observable<number>
.
Additional information:
TypeScript version: 2.5.3
My current workaround is to manually downcast the return value:
const obs = Observable.of(5);
const connectableObs = obs.pipe(
publishReplay(1)
) as ConnectableObservable<number>;
Happy to send a PR, but not sure how should I fix this properly.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:65
- Comments:17 (3 by maintainers)
Top Results From Across the Web
Compiler cannot infer return type - swift - Stack Overflow
Swift is unable to infer the return type of a function, whose parameter is a closure, and where the return type is deduced...
Read more >Understanding RxJS Multicast Operators | by Netanel Basal
It doesn't internally use the multicast operator itself, and as a result it always returns an observable, rather than a ConnectableObservable .
Read more >CHANGELOG.md - ReactiveX/rxjs - Sourcegraph
takeWhile: Now returns proper types when passed a Boolean constructor. ... pipe: Ensure that unknown is inferred for 9+ arguments. (#6212) (6fa819b) ...
Read more >rxjs@7.8.0 - jsDocs.io
A function that returns an Observable that performs rate-limiting of ... Signatures with type parameters that cannot be inferred will be ...
Read more >Build Reactive Websites with RxJS: Master Observables and ...
Return policy: Returnable until Jan 31, 2023 ... and Subjects, followed by ways to use those types with some of the operators. ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This issue still exists in rxjs 6.0 final. Reproduce:
tsc
will fail, sayingerror TS2339: Property 'connect' does not exist on type 'Observable<any>'.
. Casting theconnectableObservable
toany
and calling.connect()
works as expected.Edit: Used latest typescript 2.8.3.
Actually, if the overload signatures for
pipe
are written like this:The problem can be solved without specific reference to
ConnectableObservable
.This seems to be okay with the version of TypeScript (2.0) that RxJS uses, but I’ve not investigated this thoroughly.