How do you use TypeScript's type system to make invalid states unrepresentable in a service?
You shrink the set of values the compiler accepts: discriminated unions instead of optional-field soup, branded types so one id cannot stand in for another, and a never-typed fallback that fails the build when a variant is added. Types vanish at runtime, so input is parsed by a schema the type is inferred from.