Skip to content
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

Using publish() inside a pipe doesn't return a right type #3595

Closed
Pittan opened this issue Apr 23, 2018 · 3 comments
Closed

Using publish() inside a pipe doesn't return a right type #3595

Pittan opened this issue Apr 23, 2018 · 3 comments

Comments

@Pittan
Copy link

Pittan commented Apr 23, 2018

RxJS version:
6.0.0-uncanny-rc.7

Code to reproduce:
https://stackblitz.com/edit/rxjs6-publish-and-connect

Expected behavior:
It should be no error for TS compiler.

Actual behavior:
TS compiler outputs error, even when I added ConnectableObservable<any> to variable.

Additional information:

@evertbouw
Copy link
Contributor

evertbouw commented Apr 23, 2018

According to the TypeScript definition of pipe the output of an operator is always an Observable, but this is not the case with publish. To work around this, you can apply the operator outside of pipe:

import { interval } from 'rxjs';
import { filter, publish } from 'rxjs/operators';

const source = interval(400);

const observable = publish()(source.pipe(
  filter(x => x % 2 === 0),
));

observable.connect();

See also #2995

@Pittan
Copy link
Author

Pittan commented Apr 23, 2018

@evertbouw
Looks weird to me... but it worked perfectly! Thank you!

@Pittan Pittan closed this as completed Apr 23, 2018
@lock
Copy link

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants