You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ES6 introduces an interesting use of iterable in Promise.all(), which takes Iterable<any | Promise<any>> and returns a Promise of Array<any>, where the elements of the result array follow the sequence of the iterable.
While TypeScript is not able to determine the type of each element of the result array when the input is an iterable, it should be able to do so when the input is an array or tuple, where the type of each element is known at input. However, there is no such language feature at the moment. I think that will be possible when access to element types of a tuple in generics is supported.
Therefore, I propose that a tuple generics constraint and an element type operator be added.
For example, with tuple() being the tuple generics constraint and * being the element type operator:
(Since T is a tuple, Array<T*> is equivalent to T.)
If the tuple generics constraint and the element type operator are added, Promise.all may have 2 overloads, one takes an iterable and another takes a tuple, with the latter one offers type information for each element of the result array.
The text was updated successfully, but these errors were encountered:
FranklinWhale
changed the title
Access to element types of a tuple in generics
Suggestion: Access to element types of a tuple in generics
Jun 9, 2015
ES6 introduces an interesting use of iterable in
Promise.all()
, which takesIterable<any | Promise<any>>
and returns aPromise
ofArray<any>
, where the elements of the result array follow the sequence of the iterable.While TypeScript is not able to determine the type of each element of the result array when the input is an iterable, it should be able to do so when the input is an array or tuple, where the type of each element is known at input. However, there is no such language feature at the moment. I think that will be possible when access to element types of a tuple in generics is supported.
Therefore, I propose that a tuple generics constraint and an element type operator be added.
For example, with
tuple()
being the tuple generics constraint and*
being the element type operator:(Since T is a tuple,
Array<T*>
is equivalent to T.)If the tuple generics constraint and the element type operator are added,
Promise.all
may have 2 overloads, one takes an iterable and another takes a tuple, with the latter one offers type information for each element of the result array.The text was updated successfully, but these errors were encountered: