Pattern matching
Goal: Replace fragile switch with exhaustive match.
match is an expression — every arm produces a value. Missing variants are compile errors (SJS-E007).
Example
type Status = Active | Paused | Done
function label(s: Status): string {
return match s {
Active => "active",
Paused => "paused",
Done => "done",
}
}Key takeaways
- Arms are separated by commas.
- Exhaustiveness is enforced at compile time.
matchworks on sum types, not arbitrary strings.
Next: Sum types