Skip to content
webtype.orgwebtype.org

    ↑↓ move · ⏎ open · esc close

    No. 276 · September 28, 2026 · Gentle

    Type-level if

    Implement If<Condition, Then, Else> so the literal boolean condition selects exactly one branch.

    01

    Try the puzzle yourself

    Par 2

    Puzzle

    type-level-if.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
    • If<true, 'yes', 'no'>—
      → 'yes'
    • If<false, 'yes', 'no'>—
      → 'no'
    • If<true, 1, never>—
      → 1

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

    The solution

    type If<Condition extends boolean, Then, Else> = Condition extends true ? Then : Else

    The common wrong answer

    type If<Condition extends boolean, Then, Else> = boolean extends Condition ? Then : Else

    Assignability has a direction. boolean is not assignable to the narrower literal true, so reversing the question selects the wrong branch.

    Line by line

    1. Condition extends true ? Then : Else

      With a literal condition the check has one answer, so only one branch survives.

    Takeaway

    A conditional type is an if whose question is assignability, and the left-to-right direction is part of the meaning.

    Uses