Union of Observables cannot have piped operators
See original GitHub issueRxJS version: I tested on both v5.5 and v6.0
Code to reproduce:
(foo as Observable<number>).pipe(filter(_=>true));
(foo as Observable<string>).pipe(filter(_=>true));
(foo as Observable<number|string>).pipe(filter(_=>true));
(foo as Observable<number>|Observable<string>).pipe(filter(_=>true));
Expected behavior: All build or all fail.
Actual behavior: Line 1-3 build, line 4 fails with “TS2554: Expected 0 arguments, but got 1.”
Additional information:
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Angular Error TS2554:Expected 0 arguments, but got x on ...
1 Answer 1 · Do you think I should rename the question to Union of Observable cannot have piped operators. – Suhayb. Feb...
Read more >Filtering Types with Correct Type Inference in RxJs - Medium
A common use of the RxJs filter operator is to only allow or prevent certain types from being passed to the next pipe...
Read more >tap - RxJS
The tap operator is designed solely for such side-effects to help you remove side-effects from other operations. For any notification, next, error, or...
Read more >Merge operator - ReactiveX
mergeDelayError has fewer variants. You cannot pass it an Iterable or Array of Observables, but you can pass it an Observable that emits...
Read more >When should I unsubscribe my Subscriptions in Angular?
You can call these and simply subscribe to their observables ... By using the async pipe, you no longer have a subscription to...
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
@bowenni The issue isn’t an RxJS problem. And I doubt that it’s a TypeScript problem, either; it’s just how the resolution of overload signatures works for union types.
To see what’s going on, have a look at the overload signatures for
pipe
. ForObservable<number>
,pipe
will have signatures like:And for
Observable<string>
,pipe
will have signatures like:For the union type -
Observabe<number> | Observable<string>
- the onlypipe
signature that has parameters common to bothObservabe<number>
andObservable<string>
is the first - the signature with no parameters - so that’s the only one that’s available.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.