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.
GET /orders?status=ready&paid=false&limit=2 ignores the query entirely. Type it, and parse each value into the type it stands for — a status in the union, a real boolean, a number with a default — rejecting what does not parse.
Each filter parses into its real type, bad values are 400s, and nothing is cast.
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.
A type is a note to your future self that the compiler checks — annotating what goes in and what comes out is where most of the value is, before any advanced feature.
A raw exception string tells the caller nothing they can act on; RFC 7807 ProblemDetails gives every failure the same machine-readable shape.