feat(combineLatest): add N-args signature for observable inputs #5488
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
Adds a type signature to provide an array with more than six elements to
combineLatest
without losing the order of the input observable types. We recently had this problem at a client project and needed to resort to nestingcombineLatest
.The solution makes use of TypeScript readonly tuples. They allow for an array
[a, b]
to have the type[A, B]
instead of(A | B)[]
. With this type, we can make use ofObservedValueTupleFromArray
to get all the observed types of the tuple in the correct order.This comes with the "drawback" that the input array must be declared
as const
, else TypeScript assumes a union type per default. It would work with spreading syntax though like incombineLatestWith
, but this signature was deprecated forcombineLatest
.For this to work, the conditional type
ObservedValueTupleFromArray
must check for the narrowreadonly T[]
type, but this shouldn't be an issue asT[]
extends it.Related issue:
#5066
#4410