Skip to content

    ↑↓ move · ⏎ open · esc close

    Object shapes

    Pick

    Keeps only the named keys, and checks that they exist.

    What it is

    A mapped type over `K` rather than over `keyof T`, which is why the result is a plain object rather than a copy of the original. The constraint `K extends keyof T` is doing real work: pick a key that is not there and the error arrives at the type, not later at a property access.

    Examples

    • Pick<{ a: string; b: number }, 'a'>
      { a: string; }
    • Pick<{ a: string; b: number; c: boolean }, 'a' | 'c'>
      { a: string; c: boolean; }
    • Pick<{ readonly a: string }, 'a'>
      { readonly a: string; }

      `readonly` is carried across, because `Pick` maps over a key set derived from `T`.

    Each resolved type above was printed by TypeScript 5.9.3, not written by hand.

    What it does not do

    • It does not accept keys that are missing. That is a feature, and it is the difference between `Pick` and `Omit` — the latter accepts anything.
    • It does not distribute over a union in `T`. `Pick<A | B, K>` picks from the union as one thing rather than from each member.

    Takeaway

    When you want a subset and you want to be told about typos, `Pick` is the one with the guard rail.