Without assistance, the only thing TypeScript can prove about an argument is that it is a subtype of the parameter's annotation. Given a function (x: `foo${string}`) => void, the compiler will prove for all call sites that x is always a subtype of `foo${string}` and never an unrelated type. But it cannot prove properties outside of subtyping. It cannot directly prove that a string is exactly 6 characters long, that a string contains no spaces, that a type is non-union, or that a type satisfies many other useful properties.
The technique described here, which I call the type-validator pattern, allows us to teach the compiler to prove arbitrary properties about an argument's type at each call site, rejecting the call site if they do not hold.
Consider a simple event subscription system. Users subscribe to events by passing a dictionary of event handlers to a subscribe function. The set of valid event