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

[Type] cannot subscribe observable from array of promise's concatAll() #1436

Closed
kwonoj opened this issue Mar 8, 2016 · 3 comments
Closed
Labels
TS Issues and PRs related purely to TypeScript issues

Comments

@kwonoj
Copy link
Member

kwonoj commented Mar 8, 2016

const sources = Rx.Observable.fromArray([
  new Promise((res: any) => { res(0); }),
  new Promise((res: any) => { res(1); }),
  new Promise((res: any) => { res(2); }),
  new Promise((res: any) => { res(3); }),
]);

sources.concatAll().subscribe();

won't be allowed as

31 sources.concatAll().subscribe(
~~~~~~~~~
error TS2339: Property 'subscribe' does not exist on type 'Promise<{}>'.

This issue does not affect operator behavior.

@kwonoj kwonoj added the TS Issues and PRs related purely to TypeScript issues label Mar 8, 2016
@kwonoj kwonoj changed the title [Type] cannot subscribe array of observable's concatAll() [Type] cannot subscribe observable from array of promise's concatAll() Mar 8, 2016
@kwonoj
Copy link
Member Author

kwonoj commented Apr 6, 2016

I've thought this bit more and start to think this is somewhat expected, since via concatAll flattening and trying to access <T> directly here. It's same for other type of object as well such as number, string which in non-subscribable - I'd consider this as case for requiring explicit casting if nessary.

@david-driscoll - would you mind share opinion here? I looked into RxJS 4's type definition and seems it behaves similar.

@david-driscoll
Copy link
Member

The signature for concatAll() looks like:

export interface ConcatAllSignature<T> {
  (): T;
}

Ideally we could do something like:

interface Observable<U, T extends ObservableInput<U>> {
    concatAll(): Observable<U>;
}

The problem is, with TypeScript anyway, there is no way to make a specific prototype method have a different generic constraint than the class it's attached to. So in this scenario the only thing we can do is to return T and assume T is an Observable<U>.

To help with this problem, we can certainly make the interface a little better, so that the manual type can be given.

export interface ConcatAllSignature<T> {
  (): T;
  <R>(): Observable<R>;
}

@lock
Copy link

lock bot commented Jun 7, 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 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
TS Issues and PRs related purely to TypeScript issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants