Mapped types
A mapped type builds a new type by iterating over another type’s keys and transforming each one the same way. { [K in keyof T]: T[K] } is the identity case: keyof T produces a union of T’s property names, [K in ...] loops over each one, and T[K] looks up that property’s type — the result is a type shaped exactly like T. Change what happens to T[K] on the right and you get a genuinely new type.
You should see
true falsekeyof T— a union of every property name of T, as string literal types.[K in Union]— loops the mapped type once per member of that union, binding K to the current one.T[K]— an indexed access type, looking up the type of property K on T.
Partial<T> is roughly { [K in keyof T]?: T[K] }, Readonly<T> is { readonly [K in keyof T]: T[K] }. Learning the mapped-type syntax here is what makes the utility types in this module feel obvious rather than magical.JuniorWhat does { [K in keyof T]: T[K] } do?
It is a mapped type: keyof T produces a union of T's property names, [K in ...] iterates over each one, and T[K] looks up that property's type — so the whole expression rebuilds a type identical to T. It becomes genuinely useful once you change what happens per key, like wrapping T[K] in boolean for a "flags" type, or in Promise
What they are really testing: Basic comfort reading mapped-type syntax, the building block every utility type in this module rests on.
