For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/match/Pattern.md.

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.

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.

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

Source: ts-pattern

Re-exported unchanged from ts-pattern at the pinned version.