TypeScript · Senior · Question 30 of 75

What does the mapped type { [K in keyof T]: Box<T[K]> } produce if T is the tuple [string, number]?

Explanation

A mapped type over keyof T, where T is a tuple or array type parameter, maps the elements and preserves tuple-ness, length and modifiers. This lets you type, for example, Promise.all via { [K in keyof T]: Awaited<T[K]> }.

Further reading

Problem with a question

TypeScript · Senior · question 30

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