---
title: "matchEnum(): function in Authoring, TypeShade API reference"
description: "matchEnum, a function in Authoring. Exhaustive integer dispatch over an enumU32: matchEnum(kind, Kind, { Line: () => …, Fill: () => …, … })."
url: https://typeshade.dev/api/matchenum/
language: en
---

# `matchEnum()`

Function in Authoring

Exhaustive integer dispatch over an enumU32: `matchEnum`(kind, Kind, { Line: () => …, Fill: () => …, … }).

`import { matchEnum } from 'typeshade/core/ir'`

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

## Syntax

```ts
function matchEnum<M extends Record<string, number>, R extends string>(
  scrutinee: ReadonlyNode<ScalarKey>,
  e: EnumU32<M>,
  arms: { readonly [K in keyof M]: () => ReadonlyNode<R> },
): Node<R>
```

## Parameters

**`scrutinee` `ReadonlyNode<ScalarKey>`**

**`e` `EnumU32<M>`**

**`arms` `{ readonly [K in keyof M]: () => ReadonlyNode<R> }`**

## Return value

`Node<R>`

## Description

Every member must have an arm; omit one and `tsc` errors, since the arms type is a mapped type over the enum’s keys, so adding a member surfaces every dispatch site that does not handle it. It builds the same [`matchExpr`](https://typeshade.dev/api/matchexpr/) the hand-written form would: the last-declared member becomes the `switch` default, so the emitted code is a standard exhaustive switch. Arms are zero-argument functions, called in declaration order.

## See also

- [`enumU32`](https://typeshade.dev/api/enumu32/)
- [`matchExpr`](https://typeshade.dev/api/matchexpr/)

## Source

[`src/core/ir/node.ts`, line 2090](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/ir/node.ts#L2090), at commit af54ddad5
