Interview Q&A / TypeScript

IntermediateQuick answer1 min readUpdated 3 Oct 2026

What is a mapped type in TypeScript?

SHORT ANSWER

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

ts
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 property

What 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."

#mapped-types#keyof

Related questions

Practise more TypeScript questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open TypeScript quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.