Skip to content
webtype.orgwebtype.org#219 rebuild-partial · par 2

    ↑↓ move · ⏎ open · esc close

    No. 219 · July 27, 2026 · Gentle

    Rebuild Partial

    Implement `MyPartial<T>` so every property becomes optional. Making the value accept `undefined` is not the same thing — the key itself has to become optional.

    01

    Try the puzzle yourself

    Par 2

    Puzzle

    rebuild-partial.ts
    interface User {
      id: number
      name: string
    }
    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
    • MyPartial<User>
      { id?: number; name?: string }
    • MyPartial<{ a: string }>
      { a?: string }
    • MyPartial<{}>
      {}

    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 28, 2026

    The solution

    type MyPartial<T> = { [K in keyof T]?: T[K] }

    The common wrong answer

    type MyPartial<T> = { [K in keyof T]: T[K] | undefined }

    This widens the value type but leaves the key required: you must still write `{ id: undefined }` rather than omitting it. Optionality and "may be undefined" are genuinely different properties, and exact-equality checks can tell them apart.

    Line by line

    1. { [K in keyof T]?: T[K] }

      The `?` is a mapped-type modifier. It sits between the key clause and the colon, and it adds optionality to every key produced by the mapping.

    2. keyof T

      Mapping over `keyof T` rather than a supplied key set is what makes this apply to the whole object. Compare `Pick`, where the key set is an argument.

    Takeaway

    Modifiers (`?` and `readonly`) attach to the mapping, not the value. `-?` and `-readonly` strip them again, which is how `Required` is written.

    Uses