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

Object arguments for combineLatest and forkJoin #5362

Closed
rraziel opened this issue Mar 22, 2020 · 1 comment
Closed

Object arguments for combineLatest and forkJoin #5362

rraziel opened this issue Mar 22, 2020 · 1 comment

Comments

@rraziel
Copy link
Contributor

rraziel commented Mar 22, 2020

Feature Request

Is your feature request related to a problem? Please describe.
When extensively using combineLatest or forkJoin, especially with many arguments, it can be cumbersome to have the result as an array (e.g. you can't pluck) and I typically end up having a single:

map(([a,b,c]) => ({a,b,c}))

Except it can be with many arguments and their names are obviously longer.

Moreover, the result of a combineLatest(a,b,c) (with 7+ arguments) is a [typeof(a)|typeof(b)|typeof(c)], which is not very type-safe, e.g.:

combineLatest([
  of(true),
  of('hello world'),
  of(42)
]).pipe(
  map(([a, b, c]) => {
    // a is boolean|string|number
    // b is boolean|string|number
    // c is boolean|string|number
  })
);

Describe the solution you'd like
On top of taking an array, combineLatest and forkJoin could take an object where each field is an Observable. It would then return an object with what the observable emitted, e.g:

combineLatest({
  a: of(true),
  b: of('hello world'),
  c: of(42)
}).pipe(
  map(({a, b, c}) => ({
    // a is boolean
    // b is string
    // c is number
  })
);

Describe alternatives you've considered
Writing a pipable operator, however due to TypeScript limitations there is not much that can be done to turn the array into an object, especially after combineLatest and forkJoin already lost most of the type information for each array element.

@kwonoj
Copy link
Member

kwonoj commented Mar 22, 2020

I believe this is dupe of #5022 .

@kwonoj kwonoj closed this as completed Mar 22, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
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