TypeScript · Middle · Question 5 of 75

What is a mapped type?

type Flags<T> = { [K in keyof T]: boolean };

Explanation

[K in keyof T] iterates over the keys. You can change the value type, add or remove modifiers (readonly, ?, -?) and rename keys with as. Partial, Readonly and Record are built on mapped types.

Further reading

Problem with a question

TypeScript · Middle · question 5

Test yourself

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

Take this quiz