Skip to the page

Generics and type-level tools · mid

Utility types and implementing them

Built-in utilities (Partial, Required, Readonly, Pick, Omit, Record, ReturnType, Parameters, Awaited, NonNullable, Extract, Exclude) are small mapped or conditional types, and interviewers ask you to write them.

The notes

What you must know

  • Pick<T, K> keeps keys K; Omit<T, K> removes them (Omit is Pick of Exclude of keys).
  • Record<K, V> builds an object type with keys K: Record<Role, Permission[]> forces every role.
  • Parameters<F> and ReturnType<F> read a function's types; useful to type wrappers.
  • Partial is shallow; deep versions need recursion.
  • Common senior answer: a form update (patch: Partial<User>) => and a Pick for a component's props from a model.

The red pen

Common traps: mistake → fix

  • Mistake: "Omit is type-safe on keys"

    Fix: Omit accepts any string key without error; a stricter version uses K extends keyof T.

  • Mistake: "Partial is deep"

    Fix: it only affects the first level.

Easy to hard

Questions interviewers ask, easy to hard

  1. Implement Pick and Omit.
  2. When would you use Record vs an index signature?
  3. How do you type a function that wraps another and keeps its arguments?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview