Q17. What is a mapped type?
A mapped type iterates over keys of a type and transforms the associated properties, using syntax such as { [K in keyof T]: ... }. It underlies utility types like Partial and Readonly and can remap keys with as.
Mapped types are compile-time transformations. They do not loop over runtime object properties or modify the object.
Note
Interview approach: define the concept, explain why it matters, then mention one trade-off or limitation.
TypeScript concept
// Illustrative TypeScript contract
type Identifier = string;
const id: Identifier = "item-1";💡 The example demonstrates the compile-time contract discussed in this question.
Key Takeaways
- Explain the concept in your own words.
- Know the practical trade-off and its limits.
- Use a small example to demonstrate the idea.
Knowledge Check
Which syntax is used to iterate over keys in a mapped type?