Instruction: Explain the concept of Mapped Types and illustrate with an example.
Context: This question tests the candidate's knowledge and application of Mapped Types in TypeScript, a powerful feature for creating new types based on existing ones.
Official answer available
Preview the opening of the answer, then unlock the full walkthrough.
At its core, Mapped Types apply a given set of modifiers to each property in an existing type. This can include making properties optional, readonly, or of a different type altogether. The syntax for Mapped Types might appear complex at first glance, but it’s built on the concept of iterating over keys of any other type—akin to mapping over an object in JavaScript but at the type level.
For example, suppose we have an interface Person that we use extensively across our application:...