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

Use generic rest parameters for combineLatest, zip, merge, concat, withLatestFrom #4410

Closed
ggradnig opened this issue Dec 7, 2018 · 4 comments

Comments

@ggradnig
Copy link
Contributor

ggradnig commented Dec 7, 2018

Use generic rest parameters for combineLatest, zip, merge, concat, withLatestFrom (more than 6 input Observables)

Is your feature request related to a problem? Please describe.
There are currently no type signatures for the mentioned operators/creation functions that allow more than 6 Observables while still keeping the correct types for the subscriber (anything above creates an impractical union type).

Describe the solution you'd like
Add a signature that makes use of generic rest parameters (documented here) and mapped types. Currently, the signatures look like this:

export function combineLatest<T, T2, T3, T4, T5, T6>(v1: ObservableInput<T>, 
    v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, 
    v5: ObservableInput<T5>, v6: ObservableInput<T6>, scheduler?: SchedulerLike)
    : Observable<[T, T2, T3, T4, T5, T6]>;

This could for example be replaced with:

type CombinedObservable<T> = Observable<{
  [P in keyof T] : T[P] extends ObservableInput<infer U> ? U : never
}>

combineLatest<T extends (ObservableInput<any> | SchedulerLike)[]> (...obs: T) 
    : CombinedObservable<T>

These signatures would be more concise and enable more than 6 input Observables to be used with correct typings. The required TypeScript version is 3.0.

@cartant
Copy link
Collaborator

cartant commented Dec 7, 2018

There's a lot that can be done to improve the types, once TypeScript version 3 becomes the minimum-supported version, but that won't be until v7.

@ggradnig
Copy link
Contributor Author

ggradnig commented Dec 7, 2018

Oh I see, didn't find the minimum supported TS version for RxJS 6 anywhere. Thanks for the info, will use own typings then :)

@ggradnig ggradnig closed this as completed Dec 7, 2018
@cartant
Copy link
Collaborator

cartant commented Dec 7, 2018

Using tuples and rest parameters - necessitating a minimum of TS 3.0 - would be a breaking change for many projects, so we'll need to wait for v7 to do this. The good news is that v7 is getting close to an alpha. Also, we now have a large portion of the API surface area covered with dtslint-based typings tests - so making changes to the typings ought to be less worrying. When we do get around to taking advantage of what TS 3.0 has to offer, any contributions you're able to make would definitely be appreciated.

@ggradnig
Copy link
Contributor Author

ggradnig commented Dec 7, 2018

Okay, thanks for the detailed reasoning and update on the development status. I'll stick around for v7 and see what I can contribute :-)

@lock lock bot locked as resolved and limited conversation to collaborators Jan 6, 2019
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