# TS-Pattern

A TypeScript pattern-matching library that lets code express complex conditional logic as a single expression, with type inference and compile-time exhaustiveness checking.

TS-Pattern brings pattern matching to TypeScript, letting a program match on nested objects, arrays, tuples, sets, maps and primitive values instead of chains of if/else or switch statements. It is fully typed, with type inference that narrows values as they are matched.

The library supports an exhaustiveness check through a dedicated method that verifies every possible case has been handled, wildcards for catching any or a specific type of value, predicates, unions, intersections and exclusion patterns, and a select function for pulling out matched properties. The same pattern syntax can also validate the shape of unknown data.

It has no runtime dependencies and adds only a small amount to a bundle's size. It is installed with npm, pnpm, yarn, bun or jsr and works in any JavaScript or TypeScript project.

Website: https://github.com/gvergnaud/ts-pattern
