Annotated solution
Published September 14, 2026The 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
`${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
Wis always a single word.: Capitalize<S>The base case is the last word, and it is the only place
Capitalizeis 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.

