Skip to content
webtype.orgwebtype.org

    ↑↓ move · ⏎ open · esc close

    No. 255 · September 7, 2026 · Gentle

    First

    Implement First<T> so it produces the type of the first element of the tuple T, or never when T is empty.

    01

    Try the puzzle yourself

    Par 2

    Puzzle

    head-tuple.ts
    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
    • First<[1, 2, 3]>—
      → 1
    • First<[]>—
      → never
    • First<[string]>—
      → string

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

    The solution

    type First<T extends readonly unknown[]> = T extends [infer H, ...unknown[]] ? H : never

    The common wrong answer

    type First<T extends readonly unknown[]> = T extends [infer H] ? H : never

    A one-element pattern matches one-element tuples and nothing else. First<[string]> works, First<[1, 2, 3]> falls straight through to never, and the puzzle looks half-solved because one check passes. The pattern has to say "and then anything".

    Line by line

    1. [infer H, ...unknown[]]

      The rest is spread as unknown[] rather than inferred, because nothing here needs it. Naming what you will not use is the most common way these patterns get harder to read than they are.

    2. : never

      never is the honest answer for "there is no such element" — not undefined, which would claim there is an element and its value is missing.

    Takeaway

    Tuple patterns are exact. [H] means "a tuple of length one", and if you meant "at least one" you have to write the rest of it.

    Uses