# gvergnaud/ts-pattern

🎨 The exhaustive Pattern Matching library for TypeScript, with smart type inference.

Repository: https://github.com/gvergnaud/ts-pattern
Canonical: https://ross.abutalabs.com/products/ts-pattern
Language: TypeScript
License: MIT
License Family: permissive
Topics: pattern-matching, typescript, ts, pattern, matching, inference, type-inference, exhaustive, conditions, branching, javascript
Last push: 2026-08-10T23:33:38+00:00

## Health v2 (maintenance only)
Score: 78/100 (v2, computed 2026-09-03T02:20:16.233290+00:00)
- activity 97, release rhythm 42, longevity 100
- inputs: {"age_days": 2292, "days_push": 23, "days_rel": 311, "gap_med": 56.0, "n_releases_24m": 9}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 15137, forks 171 (observed 2026-08-28T04:11:09.263664+00:00)

## What it is
TS-Pattern is an exhaustive pattern matching library for TypeScript with smart type inference. It lets developers express complex branching conditions in a compact, typesafe way with compile-time exhaustiveness checking.

## Use cases
- match on discriminated unions in typescript
- exhaustive switch handling for adts
- validate data shape with type-safe patterns
- replace nested if-else conditions with readable matching
- extract nested values from objects and arrays with patterns

## When to choose
- you write typescript and want compile-time exhaustiveness checking over unions
- you want a tiny (~2kB) dependency-free branching utility
- you need type-safe data validation and selection in one expression

## When to avoid
- you work in plain javascript without type checking
- you only need simple switch statements with few cases
- you need runtime schema validation with detailed error messages

## Facets
- artifact type: library
- maturity: stable
- function: type-system, developer-tools
- domain: programming-languages, developer-tools, frontend, web-development
- platform: browser
- tags: pattern-matching, type-inference, exhaustiveness-checking, adt, typescript-library, nodejs, typescript, javascript

## Member repositories
- gvergnaud/ts-pattern (main) score 78

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:11:09.263664+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-29T17:06:36.304645+00:00, confidence not recorded.
  - readme: https://github.com/gvergnaud/ts-pattern (fetched 2026-08-28T04:11:09.263664+00:00, sha 9b43221aaae1)
  - registry_npm: https://registry.npmjs.org/ts-pattern (fetched 2026-08-29T08:04:45.561057+00:00, sha ff73a7bc8b8d)
- Data as of 2026-08-30T08:39:29.467469+00:00.
