Quick Contact

✉
fahimkhan20148@gmail.com
📱
+971 507 286 133
Back to Notes
August 22, 2026
typescripttype-systempattern-matching

TypeScript Satisfies Operator

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

Demo

satisfies-15-02-2026.png

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.