Skip to content
webtype.orgwebtype.org

    ↑↓ move · ⏎ open · esc close

    No. 263 · September 15, 2026 · Moderate

    From entries

    Implement FromEntries<T> so a union of [key, value] pairs becomes an object. Each key must end up with its own value, not everybody’s.

    01

    Try the puzzle yourself

    Par 3

    Puzzle

    from-entries.ts
    Stroke 1 of 3Not run yet

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

    Checks

    3
    • FromEntries<['a', 1] | ['b', 2]>—
      → { a: 1; b: 2 }
    • FromEntries<['x', string]>—
      → { x: string }
    • FromEntries<['a', 1] | ['a', 2]>—
      → { a: 1 | 2 }

    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 September 16, 2026

    The solution

    type FromEntries<T extends [PropertyKey, unknown]> = { [K in T[0]]: Extract<T, [K, unknown]>[1] }

    The common wrong answer

    type FromEntries<T extends [PropertyKey, unknown]> = { [K in T[0]]: T[1] }

    The keys are right and every value is wrong. T is still the whole union inside the mapping, so T[1] is every value at once: { a: 1 | 2; b: 1 | 2 }. Iterating over T[0] narrows the *key* you are writing, not the T you are reading from.

    Line by line

    1. Extract<T, [K, unknown]>

      This is the re-narrowing step. For each K it pulls out only the pairs whose first element is that key, discarding the rest of the union.

    2. FromEntries<['a', 1] | ['a', 2]>

      Two pairs share a key, so the extraction keeps both and the value really is 1 | 2. A union here is correct — the earlier one was correct too, just attached to the wrong keys.

    Takeaway

    Iterating over a union does not narrow the union itself, only the key you are producing. If you need the matching member back, Extract is how you ask for it.

    Uses