Skip to content
webtype.orgwebtype.org

    ↑↓ move · ⏎ open · esc close

    No. 261 · September 13, 2026 · Moderate

    Title case

    Implement TitleCase<S> so every space-separated word in S gets a capital first letter.

    01

    Try the puzzle yourself

    Par 3

    Puzzle

    title-case.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
    • TitleCase<'hello world'>—
      → 'Hello World'
    • TitleCase<'foo'>—
      → 'Foo'
    • TitleCase<'a b c'>—
      → 'A B C'

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

    The solution

    type TitleCase<S extends string> =
      S extends `${infer W} ${infer Rest}` ? `${Capitalize<W>} ${TitleCase<Rest>}` : Capitalize<S>

    The common wrong answer

    type TitleCase<S extends string> = Capitalize<S>

    Capitalize capitalizes a string, singular — the first character of the whole thing and nothing else. "hello world" becomes "Hello world". The built-in has no notion of a word, so anything word-shaped has to be found by you first.

    Line by line

    1. `${infer W} ${infer Rest}`

      The literal space between the placeholders is what makes this a word splitter. Inference stops at the first one it finds, so W is always a single word.

    2. : Capitalize<S>

      The base case is the last word, and it is the only place Capitalize is applied to the whole remaining string — by then, the whole remaining string *is* one word.

    Takeaway

    The intrinsic string types work on whole strings. Words, segments and paths are things you carve out with template patterns first, and only then hand over.

    Uses