typescript
Exhaustiveness check using satisfies never in switch
In the default branch, TypeScript narrows proto to whatever union members weren't handled. If all cases are covered, proto becomes never and the check passes silently. If you miss a case (like "raw" here), proto still has a remaining type, so satisfies never produces a compile-time error telling you exactly which variant you forgot to handle.
type Proto = "tcp" | "http1" | "raw"
const proto = "tcp" as Proto
switch (proto) {
case "tcp":
case "http1":
break;
default:
proto satisfies never; // <-- Type '"raw"' does not satisfy the expected type 'never'.
}typescript
lubosmato