API Reference / @evolu/common / Function / exhaustiveCheck
Function: exhaustiveCheck()
function exhaustiveCheck(value): never;
Defined in: packages/common/src/Function.ts:30
Helper function to ensure exhaustive matching in a switch statement. Throws an error if an unhandled case is encountered.
Remember, it's useful only when we don't return anything from the switch statement. Otherwise, a return type of a function is enough.
Example
type Color = "red" | "green" | "blue";
function handleColor(color: Color): void {
switch (color) {
case "red":
console.log("Handling red");
break;
case "green":
console.log("Handling green");
break;
case "blue":
console.log("Handling blue");
break;
default:
exhaustiveCheck(color); // Ensures all cases are handled
}
}
Parameters
Parameter | Type |
---|---|
value | never |
Returns
never