Template literal types, and a string that is checked

4.1 in November lets a type be built from string literals, which turns a naming convention into something the compiler enforces.

type Method = 'get' | 'post';
type Route  = `/api/${string}`;
type Handler = `handle${Capitalize<Method>}`;   // 'handleGet' | 'handlePost'

function call(url: Route) {}
call('/api/orders');   // ok
call('/orders');       // error

The intrinsic helpers — Capitalize, Uppercase and their inverses — are what make this practical rather than a curiosity. The obvious use is checking a route or an event name against a convention at compile time. It is also easy to build something unreadable: a type computed through four template literals is a type nobody can debug, and the error messages do not help.