What is a mapped type in TypeScript?
A mapped type builds a new object type by looping over the keys of another type with the syntax { [K in keyof T]: ... }. Partial, Readonly and Pick are all mapped types written this way.
Explain it simply
A mapped type is a photocopier with a rule. You feed it a form, and it produces a new form with the same fields, but each field is changed by your rule: make it optional, make it read-only, change its type.
[K in keyof T] means "for every key K of T". The part after the colon decides the new property type, and T[K] refers to the original type of that key.
Example
interface Student { name: string; roll: number }
// Every property becomes boolean
type Flags<T> = { [K in keyof T]: boolean };
type StudentFlags = Flags<Student>;
// { name: boolean; roll: boolean }
// Re-implementing built-ins
type MyPartial<T> = { [K in keyof T]?: T[K] };
type MyReadonly<T> = { readonly [K in keyof T]: T[K] };
const p: MyPartial<Student> = { name: "Asha" }; // roll is optional
const r: MyReadonly<Student> = { name: "Ravi", roll: 7 };
// r.roll = 8; // Error: read-only propertyWhat to say in the interview
"A mapped type iterates over the keys of a type with [K in keyof T] and produces a new type, optionally changing each property's type or modifiers. Built-in utilities like Partial, Readonly and Pick are just mapped types, which is why I can write custom ones when needed."