# ts-pattern: 6.0 out of 10

Reasonable, with limits. 5th of 9 in [Typed errors and functional programming](https://elestia.ai/opensource/typed-errors/index.md).

ts-pattern is a small, mature library for exhaustive, type-safe pattern matching in TypeScript, with no dependencies. It is an excellent complement to typed errors, but it does not provide Result or Either types itself. To handle errors as values you pair it with a Result library such as neverthrow, better-result or Effect.

**Best for:** TypeScript teams that model outcomes and errors as discriminated unions and want the compiler to check that every case is handled.

## Scores

- **Overall: 6.0** (likely 4.9 to 7.3)
  - Claude Opus 5.5 (6.0): It is a high-quality, well-maintained tool, but it does only part of this category's job. It makes handling error unions exhaustive, yet you still need a Result library to represent and chain failures. Pick it as a companion to neverthrow, better-result or plain discriminated unions, not as the category's main choice.
  - GPT-6.2 Sol (5.9): ts-pattern earns its place when a project already returns typed errors and needs exhaustive handling of nested variants. True Myth supplies Results and typed async Tasks, and Effect carries a typed error channel through workflows, so both cover more of the category’s core job. Recent fixes support adopting it as a matcher, while the sparse release cadence and slower relative download growth temper the recommendation.
- **Needed by many: 4.8** (likely 3.7 to 6.4)
  - Claude Opus 5.5 (5.0): Pattern matching on discriminated unions is useful in many TypeScript codebases, not only for errors. For this category's job, though, it serves only the 'handle every case' half, and only for TypeScript users. That puts it at a moderate niche within the category.
  - GPT-6.2 Sol (4.5): Exhaustive matching is useful in frontend and backend TypeScript when errors, states, or events have several variants. In this category, it mainly helps teams that already model failures as unions. The State of JavaScript survey shows interest in pattern matching, while demand for this specific error-handling approach is harder to measure.
- **Helps a lot: 5.8** (likely 4.8 to 7.1)
  - Claude Opus 5.5 (6.0): As a pattern matcher it is the best-known option, with excellent inference and exhaustiveness checks. For typed errors it lacks Result types, combinators and async error chaining, which neverthrow, better-result and Effect provide. Runtime speed is reasonable but behind compiled matchers.
  - GPT-6.2 Sol (5.6): Version 5.9.2 narrows nested cases well and makes invalid-pattern diagnostics easier to read. The documented `.exhaustive()` call gives developers and coding agents a compiler check for omitted branches. Modeling errors, converting exceptions, and composing typed async failures require application code or another library. Type-checking cost grows with complex patterns, and runtime overhead depends on the workload.
- **Holds up over time: 6.6** (likely 5.2 to 8.0)
  - Claude Opus 5.5 (6.5): The project is active: it had a push the day before collection, 58 commits in the last year and releases in October 2026. It rests mostly on one maintainer, and 33 pull requests are open. The v5 API has been stable for years, and breaking changes are rare and limited to type checks.
  - GPT-6.2 Sol (6.7): There were 58 commits in the past year, and the October patches improved compiler performance and diagnostics. Both patches landed in October 2026 after nearly a year between releases, and some inference reports have stayed open for months. Outside contributors landed fixes, while both recent releases came from the same maintainer.
- **Used widely: 5.9** (likely 4.7 to 7.1)
  - Claude Opus 5.5 (7.0): It has about 39M downloads per 4 weeks, 15k stars and 3.4k dependent repositories, which is broad direct use. Downloads grew 3.2x in a year, below the 4.1 median, so its share is slipping slightly. Part of the volume comes from transitive installs.
  - GPT-6.2 Sol (4.7): Four-week npm downloads rose from 12.2 million to 39.1 million, a 3.22× increase below the catalog’s 4.1× median and neverthrow’s 4.90×. The indexed repository count trails True Myth and exceeds neverthrow’s, while 15 Bluesky posts show attention comparable to True Myth. Automated installs and downstream tooling inflate downloads, and the indexed dependents cover only part of GitHub.
- **Vouched for: 6.3** (likely 4.9 to 7.7)
  - Claude Opus 5.5 (6.0): Many projects depend on it, and other libraries such as ArkType and schematch use it as the reference to compare against. Developers on Bluesky praise it. There is no survey data and no independent production write-up about using it for error handling.
  - GPT-6.2 Sol (6.5): Documenso’s signing package and ESLint React’s Web API plugin both depend on it. Users report that it makes nested result handling easier to read, and independent benchmarks show runtime trade-offs. The clearest endorsements are for pattern matching and cover a narrower use than typed error handling across an application.
- **Safe: 7.7** (likely 6.5 to 8.8)
  - Claude Opus 5.5 (8.0): It has zero dependencies, no advisories ever and an MIT licence. The OpenSSF Scorecard is weak at 4.1: there is no branch protection, no security policy and little code review. Publishing rests on a single maintainer.
  - GPT-6.2 Sol (7.3): The MIT package has zero runtime dependencies and zero OSV advisories in the snapshot. The OpenSSF score is 4.1, with weak code review and zero scores for branch protection, security policy, and fuzzing. GitHub verifies the latest tag, and the package defines a test-and-build step before `npm publish`. Registry provenance and the number of authorized npm publishers remain unverified.

## Good

- `.exhaustive()` gives compile-time errors when a union case, such as a new error variant, is left unhandled.
- It has zero dependencies, a tiny bundle and MIT licence, so it adds almost no supply-chain risk.
- Type inference narrows matched values deeply, including nested objects, P.union, P.select and the new P.record patterns.
- It has been stable on v5 for years, and recent releases mostly add features and speed up type checking.

## Bad

- It has no Result or Either type and no helpers to chain async errors, so it covers only half of the category's job.
- Runtime matching is slower than a plain switch or compiled matchers such as ArkType's match.
- Large matches can slow the TypeScript compiler, and it requires TypeScript 5 or later in strict mode.
- Releases depend mostly on one maintainer, and pull requests pile up (33 open against 104 merged).

## The numbers

- Downloads, 4 weeks: 39M
- In a year: ×3.2
- GitHub stars: 15k
- Commits, 12 months: 58
- Last npm release: Oct 2026
- Advisories, 24 months: 0
- Licence: MIT
- GitHub: https://github.com/gvergnaud/ts-pattern
- npm: https://www.npmjs.com/package/ts-pattern

Scores run from 0 to 10 and are the mean of the scores of AI reviewers (Claude Opus 5.5, GPT-6.2 Sol), made on 22 November 2026 from GitHub, npm, OSV, OpenSSF Scorecard, ecosyste.ms, Hacker News and Bluesky data and a web search. The ecosyste.ms count of repositories that use a project is far too low for projects that grew in the last few years, and some reviews quote it. Overall is the reviewers' own judgement for a new project today, not an average of the parts. An AI wrote them and can be wrong.
