intermediate

Utility and mapped types

Transform object types with Partial, Pick, Omit, Record, keyof, indexed access, and mapped modifiers.

Utility types transform existing types so you do not duplicate object shapes. `Pick` and `Omit` select fields, `Partial` and `Required` adjust optionality, `Readonly` changes assignment rules, `Record` creates keyed maps, and mapped types generalize these transformations with `keyof` and indexed access.

					type UserPatch = Partial<Pick<User, 'name' | 'email'>>;
type UserKeys = keyof User;
				

Derive when contracts are truly linked. Over-derived types can hide intent if the public API should evolve independently.

On interviews: explain with a concrete example and name what interviewers probe in production code.

Common pitfalls: mixing similar APIs and forgetting edge cases during live coding.

The trade-off is often clarity versus safety or expressiveness versus maintainability. Checklist:

  • Derive linked contracts.
  • Use keyof deliberately.
  • Name important transformed shapes.