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
{{ message }}
Repository navigation
Suggestion: Access to element types of a tuple in generics #3420
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.
Activity
[-]Access to element types of a tuple in generics[/-][+]Suggestion: Access to element types of a tuple in generics[/+]danquirk commentedon Jul 9, 2015
May be that some extension of
typeofis the right way to approach this if we were to go down this path.mhegazy commentedon Dec 10, 2015
The original proposal should be handled by #5453. The promise.all case has improved by adding oveloads in #5935. closing in favor of #5453.