Skip to Content
P Not

Last Updated: 3/6/2026


P.not Patterns

P.not lets you match on everything but a specific value. It’s a function taking a pattern and returning the opposite pattern.

import { match, P } from 'ts-pattern'; type Input = boolean | number; const toNumber = (input: Input) => match(input) .with(P.not(P.boolean), (n) => n) // n: number .with(true, () => 1) .with(false, () => 0) .exhaustive(); console.log(toNumber(2)); // => 2 console.log(toNumber(true)); // => 1