TypeScript · Senior · Question 43 of 75

How do you type a Promise.all-like function over a tuple of promises?

Explanation

[...T] hints to infer a tuple rather than an array, and the homomorphic mapped type unwraps each element: all([fetchUser(), fetchPosts()]) → Promise<[User, Post[]]>. Versions with any or a single T lose positional types.

Further reading

Problem with a question

TypeScript · Senior · question 43

Test yourself

Take the TypeScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz