TypeScript Satisfies Operator
This demonstrates how we can use the satisfies operator in TypeScript with a switch statement to achieve exhaustive matching.
Demo

type Role = 'admin' | 'editor' | 'viewer' | "superadmin";
function setRole(role: Role) {
switch (role) {
case 'admin':
console.log('You have full access.');
break;
case 'editor':
console.log('You can edit content.');
break;
case 'viewer':
console.log('You can view content.');
break;
default:
// This will give an error if a role (like 'superadmin') is unhandled
console.log(`Unknown role. ${role satisfies never}`);
}
}
Explanation
The above code should give a compilation error:
Type '"superadmin"' does not satisfy the expected type 'never'.
This ensures that whenever a new Role is added, the compiler forces us to handle it in the switch statement. This is similar to exhaustive pattern matching in languages like Rust. It provides a safety net that is much better than discovering unhandled cases in runtime logs.
