> For AI agents: the complete documentation index is available at https://massaman.dev/llms.txt, the full documentation bundle is available at https://massaman.dev/llms-full.txt.

# Pattern ts-pattern

The type-level representation of a pattern. Used when you need to type a pattern variable or write a helper that accepts patterns.

```typescript
import { type Pattern, match, P } from 'massaman/match'
```

## Usage

Most code doesn't reference `Pattern` directly — you just inline patterns into `.with(…)`. Reach for it when storing a pattern in a variable or returning one from a helper.

```typescript
import { type Pattern, match, P } from 'massaman'

type Event = { kind: 'click' } | { kind: 'key'; code: string }

const isInterestingKey: Pattern<Event> = {
  kind: 'key',
  code: P.union('Enter', 'Escape'),
}

match(event)
  .with(isInterestingKey, ({ code }) => `confirm: ${code}`)
  .otherwise(() => 'ignored')
```

## See also

- [`P`](https://massaman.dev/reference/match/P.md) — pattern primitives
- [`match`](https://massaman.dev/reference/match/match.md)
- [ts-pattern README](https://github.com/gvergnaud/ts-pattern#readme)


Source: ts-pattern

Re-exported unchanged from [`ts-pattern`](https://github.com/gvergnaud/ts-pattern) at the [pinned version](https://github.com/zrosenbauer/massaman/blob/main/docs/_meta/upstream-versions.json).
