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

Interface for ConnectableObservableLike is not exposed #6529

Closed
DaSchTour opened this issue Jul 19, 2021 · 2 comments · Fixed by #6531
Closed

Interface for ConnectableObservableLike is not exposed #6529

DaSchTour opened this issue Jul 19, 2021 · 2 comments · Fixed by #6531
Assignees
Labels
7.x Issues and PRs for version 6.x bug Confirmed bug

Comments

@DaSchTour
Copy link

Bug Report

Current Behavior
Interface for ConnectableObservableLike is not exposed

Expected behavior
Interface for ConnectableObservableLike is exposed.

Reproduction

Try to add type definition to the example from docs.

import { connectable, timer } from 'rxjs';
// suggested refactor
const tick$ = connectable(timer(1_000), {
  connector: () => new Subject<number>(),
  resetOnDisconnect: false
});

First try

import { connectable, timer, ConnectableObservableLike } from 'rxjs';
// suggested refactor
const tick$: ConnectableObservableLike<number> = connectable(timer(1_000), {
  connector: () => new Subject<number>(),
  resetOnDisconnect: false
});

Result: TS2305: Module '"rxjs"' has no exported member 'ConnectableObservableLike'.

Second try

import { connectable, timer, ConnectableObservable } from 'rxjs';
// suggested refactor
const tick$: ConnectableObservable<number> = connectable(timer(1_000), {
  connector: () => new Subject<number>(),
  resetOnDisconnect: false
});

Result: TS2740: Type 'ConnectableObservableLike ' is missing the following properties from type 'ConnectableObservable ': subjectFactory, _subject, _refCount, _connection, and 3 more.

Environment

  • RxJS version: 7.2.0
@benlesh benlesh self-assigned this Jul 21, 2021
@benlesh benlesh added 7.x Issues and PRs for version 6.x bug Confirmed bug labels Jul 21, 2021
@benlesh
Copy link
Member

benlesh commented Jul 21, 2021

Really, you shouldn't need to explicitly type tick$, however, if you absolutely must, a workaround would be to use ReturnType:

import { connectable, timer } from 'rxjs';

const tick$: ReturnType<typeof connectable> = connectable(timer(1_000), {
  connector: () => new Subject<number>(),
  resetOnDisconnect: false
});

Ideally, long term, I'd love to have ConnectableObservableLike just be ConnectableObservable... Mostly because I don't like the name. For now, I guess we'll have to figure something else out.

Perhaps we can just rename ConnectableObservableLike to Connectable and expose it. 🤔

benlesh added a commit to benlesh/rxjs that referenced this issue Jul 21, 2021
benlesh added a commit to benlesh/rxjs that referenced this issue Jul 21, 2021
@DaSchTour
Copy link
Author

DaSchTour commented Jul 21, 2021

Okay. In this example it might work. But what if I'm in a class?

class Sample {
  // that's not a nice solution?
  public $tick: any;

  init() {
    this.tick$ = connectable(timer(1_000), {
      connector: () => new Subject<number>(),
      resetOnDisconnect: false
    });
  }
  
   connect() {
     this.tick$.connect():
   }
}

And with the ReturnType<typeof connectable> workaround I lose all type information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
7.x Issues and PRs for version 6.x bug Confirmed bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants