Skip to content
webtype.orgwebtype.org#246 object-entries · par 4

    ↑↓ move · ⏎ open · esc close

    No. 246 · August 29, 2026 · Hard

    Entries

    Implement `ObjectEntries<T>` so it produces the union of `[key, value]` pairs — the type-level shape of `Object.entries`. Each pair must keep its own key matched to its own value.

    01

    Try the puzzle yourself

    Par 4

    Puzzle

    object-entries.ts
    Stroke 1 of 4Not run yet

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

    Checks

    3
    • ObjectEntries<{ a: string; b: number }>
      ['a', string] | ['b', number]
    • ObjectEntries<{ x: 1 }>
      ['x', 1]
    • ObjectEntries<{}>
      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 August 30, 2026

    The solution

    type ObjectEntries<T> = { [K in keyof T]: [K, T[K]] }[keyof T]

    The common wrong answer

    type ObjectEntries<T> = [keyof T, T[keyof T]]

    This produces a single pair whose halves are both unions: `["a" | "b", string | number]`. That type permits `["a", number]` — a key paired with the wrong value — because the correlation between key and value was lost the moment both were collapsed to unions independently.

    Line by line

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

      Inside the mapping, `K` is one specific key at a time, so `T[K]` is that key’s own value type. The pairing is built while the correlation still exists.

    2. [keyof T]

      Only now is everything collapsed into a union — and by this point each pair is already sealed, so no key can drift onto another key’s value.

    Takeaway

    Distribute first, collapse last. Once two related things have been turned into separate unions their relationship is gone, and no amount of later work can pair them back up correctly.

    Uses