[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [Function](https://evolu.dev/docs/api-reference/common/Function) › exhaustiveCheck

```ts
function exhaustiveCheck(value: never): never;
```

Defined in: [packages/common/src/Function.ts:99](https://github.com/evoluhq/evolu/blob/59dabb7c56c68040b30d3919013adeb2b40bad10/packages/common/src/Function.ts#L99)

Helper function to ensure exhaustive matching in a switch statement. Throws
an error if an unhandled case is encountered.

### Example

```ts

type Color = "red" | "green" | "blue";
const handled: Array<string> = [];

const handleColor = (color: Color): void => {
  switch (color) {
    case "red":
      handled.push("Handling red");
      break;
    case "green":
      handled.push("Handling green");
      break;
    case "blue":
      handled.push("Handling blue");
      break;
    default:
      exhaustiveCheck(color);
  }
};

handleColor("blue");
assertEqual(handled, ["Handling blue"]);
```

Use this primarily in side-effect switches (`void` branches). For
value-producing switches, TypeScript can enforce exhaustiveness without a
`default` branch in either of the following styles.

### Return from every case

```ts

type Color = "red" | "green" | "blue";

const colorToHex = (color: Color): string => {
  switch (color) {
    case "red":
      return "#ff0000";
    case "green":
      return "#00ff00";
    case "blue":
      return "#0000ff";
  }
};

assertEqual(colorToHex("green"), "#00ff00");
```

### Assign in every case

```ts

type Input =
  | { readonly type: "Mutate" }
  | { readonly type: "Query" }
  | { readonly type: "Export" };

const inputToKind = (input: Input): "A" | "B" | "C" => {
  let result: "A" | "B" | "C";

  switch (input.type) {
    case "Mutate":
      result = "A";
      break;
    case "Query":
      result = "B";
      break;
    case "Export":
      result = "C";
      break;
  }

  return result;
};

assertEqual(inputToKind({ type: "Query" }), "B");
```