Skip to Content
Literals

Last Updated: 3/6/2026


Literal Patterns

Literals are primitive JavaScript values, like numbers, strings, booleans, bigints, symbols, null, undefined, or NaN.

import { match } from 'ts-pattern'; const input: unknown = 2; const output = match(input) .with(2, () => 'number: two') .with(true, () => 'boolean: true') .with('hello', () => 'string: hello') .with(undefined, () => 'undefined') .with(null, () => 'null') .with(NaN, () => 'number: NaN') .with(20n, () => 'bigint: 20n') .otherwise(() => 'something else'); console.log(output); // => 'number: two'