P
The pattern primitives namespace. Builds patterns that match by type, structure, or predicate.
Source: ts-pattern
Most of P is re-exported from ts-pattern. Massaman extends it with P.ok and P.err for matching Result values—see P.ok and P.err below.
Primitives
P.ok
Matches the Ok variant of a Result<T>. With no argument it is equivalent to { ok: true }; with an argument it applies that pattern to value.
Inside the P.ok() arm, the matched value is narrowed to Ok<T> — value is typed as T, error is null.
Pass a pattern to constrain the contained value:
P.err
Matches the Err variant of a Result<T>. With no argument it is equivalent to { ok: false }; with an argument it applies that pattern to error.
Inside the P.err() arm, the matched value is narrowed to Err — error is Error, value is null.
Examples
See also
match— multi-arm dispatchisMatching— predicate form- ts-pattern README — Patterns — full reference for the primitives we re-export
- Pattern matching concept guide
- Result & Errors concept guide