question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Union of Observables cannot have piped operators

See original GitHub issue

RxJS 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:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cartantcommented, Mar 14, 2018

@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. For Observable<number>, pipe will have signatures like:

pipe(): Observable<number>
pipe<A>(op1: OperatorFunction<number, A>): Observable<A>
...

And for Observable<string>, pipe will have signatures like:

pipe(): Observable<string>
pipe<A>(op1: OperatorFunction<string, A>): Observable<A>
...

For the union type - Observabe<number> | Observable<string> - the only pipe signature that has parameters common to both Observabe<number> and Observable<string> is the first - the signature with no parameters - so that’s the only one that’s available.

0reactions
lock[bot]commented, Jun 5, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found