Union types and narrowingintermediate
A discriminated union makes impossible states impossible: one status field the compiler forces you to handle, instead of three booleans that can contradict each other.
A transfer payment with no reference crashed the receipt printer. Payment is one shape with optional fields, so nothing ties a reference to a transfer. Make that payment impossible to build — then add USSD and let the compiler show you the one place that needs it.
Wrong data for a variant is refused, the switch is exhaustive, and all four kinds print.
Published in full, before you start — every point is one of these and there is nothing else. Each one runs your code; it is not a search for keywords.
A discriminated union makes impossible states impossible: one status field the compiler forces you to handle, instead of three booleans that can contradict each other.