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

Cannot call connect() after using publish() #3713

Closed
Niladri24dutta opened this issue May 20, 2018 · 2 comments
Closed

Cannot call connect() after using publish() #3713

Niladri24dutta opened this issue May 20, 2018 · 2 comments

Comments

@Niladri24dutta
Copy link

Niladri24dutta commented May 20, 2018

In order to create hot observable i was following the below approach

  1. Create Observable from interval()
  2. Publish that Observable using publish() to create a ConnectableObservable
  3. Call connect() on that ConnectableObservable

But I am getting the below error -

Property 'connect' does not exists on type Observable. I knowconnectexists only onConnectableObservable` but in Rxjs 5 this below code was working fine.

let $hotstream = Observable.interval(1000)
                           .take(6)
                           .publish();
$hotstream.connect();

RxJS version: 6.0.0

Code to reproduce: This is my code for Rxjs 6

let $hotstream = interval(1000).pipe(take(6),publish());
$hotstream.connect()

Expected behavior: Should be able to call connect after using publish.

Actual behavior: I have to perform an explicit cast like below to call connect.
let $hotstream = <ConnectableObservable<any>>interval(1000).pipe(take(6),publish()); $hotstream.connect();
P.S The same issue is occurring for refCount.

Additional information: Is it required to do an explicit casting like this to call connect() now?
I also noticed few changes in the publish method from 5x to 6x version.
in 5x version the below signature was called -
export function publish<T>(this: Observable<T>): ConnectableObservable<T>;
But in 6x version the signature has changed to -
export function publish<T>(): UnaryFunction<Observable<T>, ConnectableObservable<T>>; which basically returns a function that accepts an Obervable parameter and returns a ConnectableObservable<T>. So what is the best way to call connect in 6x version?

@cartant
Copy link
Collaborator

cartant commented May 20, 2018

See #2972.

@benlesh
Copy link
Member

benlesh commented May 21, 2018

Closing as duplicate.

@benlesh benlesh closed this as completed May 21, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jun 20, 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

3 participants