Skip to content
webtype.orgwebtype.org#212 rebuild-pick · par 2

    ↑↓ move · ⏎ open · esc close

    No. 212 · July 20, 2026 · Gentle

    Rebuild Pick

    Implement `MyPick<T, K>` so it keeps only the keys named in `K`. This is the built-in `Pick`, written by hand — one mapped type, no conditionals.

    01

    Try the puzzle yourself

    Par 2

    Puzzle

    rebuild-pick.ts
    interface Todo {
      title: string
      description: string
      done: boolean
    }
    Stroke 1 of 2Not run yet

    Replace ??? — your solution is checked against the cases below. Tab indents; press Escape then Tab to move focus out.

    Checks

    3
    • MyPick<Todo, 'title'>
      { title: string }
    • MyPick<Todo, 'title' | 'done'>
      { title: string; done: boolean }
    • MyPick<Todo, never>
      {}

    How a check is judged Exact type equality, not assignability — an intersection is not the same as the flattened object.

    How everyone did

    Fewer than 5 people have solved this one so far. The distribution appears once there is enough of a sample to mean anything.

    Short game

    Fewest characters

    No public scores yet.

    Archive
    02

    Annotated solution

    Published July 21, 2026

    The solution

    type MyPick<T, K extends keyof T> = { [P in K]: T[P] }

    The common wrong answer

    type MyPick<T, K extends keyof T> = { [P in keyof T]: T[P] }

    Mapping over `keyof T` copies the whole object — `K` is never consulted. The clause after `in` is the key set you are building, not the one you are reading from.

    Line by line

    1. { [P in K]: ... }

      `K` is a union of literal keys. A mapped type distributes over that union, producing one property per member.

    2. T[P]

      An indexed access. Because `K extends keyof T`, `P` is always a real key of `T`, so this never widens to `unknown`.

    Takeaway

    A mapped type reads `{ [Name in KeySet]: ValueType }`. Everything else in this track is a variation on that shape.

    Uses