ts-pattern
Reasonable, with limits. 5th of 9 typed errors and functional programming.
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
Overall6.0
How strongly do we recommend it for a new project today?
Claude Opus 5.5: 6.0, likely 5.0 to 7.5
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.
- npm downloadsLast4Weeks: Widely used, but growth is below the median
- pkgpulse.com/guides/effect-ts-vs-fp-ts-vs-neverthrow-2026: Typed-error recommendations focus on Result and Effect libraries
- github.com/gvergnaud/ts-pattern/releases: Active and stable release line
GPT-6.2 Sol: 5.9, likely 4.8 to 7.0
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.
- github.com/gvergnaud/ts-pattern/blob/v5.9.2/README.md: The API matches and narrows values supplied by the caller.
- true-myth.dev/guide/introduction/tutorial/task: True Myth documents typed async success and failure.
- effect.website/docs/v3/additional-resources/effect-vs-neverthrow: Shows how Effect and neverthrow compose typed failures.
- github.releasesLastYear, npm.downloadsLast4Weeks, npm.downloadsSame4WeeksYearAgo, medianDownloadsRatio: Two releases in the past year and download growth below the catalog median.
Needed by many4.8
How many developers need a tool for this job?
Claude Opus 5.5: 5.0, likely 4.0 to 7.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.
- github description: Describes itself as a pattern-matching library, not an error-handling library
- unpkg.com/ts-pattern@5.6.2/README.md: TypeScript-only; requires TS 5 and strict mode
GPT-6.2 Sol: 4.5, likely 3.4 to 5.8
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.
- 2025.stateofjs.com/en-US/features: 2,275 respondents selected pattern matching as a missing language feature.
- github.com/gvergnaud/ts-pattern/blob/v5.9.2/README.md: Examples cover nested results, state, and events.
- reddit.com/r/typescript/comments/1mvinj4/exhaustive_switch_expressions_in_typescript: Users describe the strongest payoff for nested unions.
Helps a lot5.8
How well does it do the job for those who need it?
Claude Opus 5.5: 6.0, likely 5.0 to 7.5
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.
- github.com/gvergnaud/ts-pattern/releases: Recent releases add P.record and .narrow() and speed up exhaustive type checks
- arktype.io/docs/blog/2.1: ArkType calls ts-pattern a great API with reasonable performance, but says its own matcher is faster
- github.com/mmkal/schematch: Self-reported benchmark from a competing library shows ts-pattern several times slower
- pkgpulse.com/guides/effect-ts-vs-fp-ts-vs-neverthrow-2026: Typed-error guides recommend Result libraries and do not mention ts-pattern
GPT-6.2 Sol: 5.6, likely 4.6 to 6.7
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.
- github.com/gvergnaud/ts-pattern/blob/v5.9.2/README.md: Documents nested narrowing, exhaustive checks, and compiler cost.
- github.com/gvergnaud/ts-pattern/releases/tag/v5.9.2: Clearer pattern types in diagnostics, with generic overload errors still possible.
- github.com/mmkal/schematch: An alternative matcher’s benchmarks show runtime overhead in several workloads.
- true-myth.dev/guide/introduction/tutorial/result: True Myth provides typed Results and exception conversion.
- true-myth.dev/guide/introduction/tutorial/task: True Myth provides a typed async failure channel.
Holds up over time6.6
Will it still be a good choice in two years?
Claude Opus 5.5: 6.5, likely 5.0 to 8.0
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.
- github commitsLastYear: 58 commits; 2 releases last year
- github openPullRequests: 33 open versus 104 merged
- scorecard Maintained: Score of 10
- github.com/gvergnaud/ts-pattern/releases: Steady minor releases on v5 with no major version bump
GPT-6.2 Sol: 6.7, likely 5.4 to 7.9
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.
- github.commitsLastYear, github.releasesLastYear, github.pushedAt: 58 commits, two releases, and a November push.
- github.com/gvergnaud/ts-pattern/releases: Release history shows the gap and the same publisher for both October patches.
- github.com/gvergnaud/ts-pattern/releases/tag/v5.9.1: Outside contributions shipped alongside TypeScript 7 compatibility work.
- github.com/gvergnaud/ts-pattern/issues: Open reports include longstanding inference and exhaustiveness edge cases.
Used widely5.9
How many use it, and is that growing?
Claude Opus 5.5: 7.0, likely 6.0 to 8.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.
- npm downloadsLast4Weeks: 39.1M, up from 12.2M a year before (ratio 3.2, below the median of 4.1)
- dependents: 3,442 repos and 334 packages; fewer than fp-ts and True Myth, more than neverthrow
- github stars: 15.2k stars, second in the category after Effect
GPT-6.2 Sol: 4.7, likely 3.4 to 6.1
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.
- npm.downloadsLast4Weeks, npm.downloadsSame4WeeksYearAgo, medianDownloadsRatio: Absolute downloads grew while relative download share slipped.
- dependents, github.stars, bluesky.posts, peers: 3,442 indexed repos, 334 npm dependents, 15,224 stars, and 15 Bluesky posts.
- github.com/Rel1cx/eslint-react/blob/main/plugins/eslint-plugin-react-web-api/package.json: ESLint React’s Web API plugin pulls ts-pattern in as a dependency.
Vouched for6.3
Who stands behind it being good?
Claude Opus 5.5: 6.0, likely 4.5 to 7.5
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.
- arktype.io/docs/blog/2.1: Used as the reference matcher in ArkType's comparison
- bluesky: 15 posts, mostly positive user remarks
- dev.to/tauantcamargo/how-ts-pattern-can-improve-your-code-readability-37dd/comments: A commenter says its value is type safety more than readability
GPT-6.2 Sol: 6.5, likely 5.2 to 7.8
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.
- github.com/documenso/documenso/blob/main/packages/signing/package.json: Documenso declares ts-pattern in its signing package’s dependencies.
- github.com/Rel1cx/eslint-react/blob/main/plugins/eslint-plugin-react-web-api/package.json: An ESLint React plugin declares a runtime dependency on v5.9.2.
- reddit.com/r/typescript/comments/1mvinj4/exhaustive_switch_expressions_in_typescript: A user shows exhaustive rendering of a nested success and error union.
- github.com/bdbaraban/ts-pattern-benchmark: Independent microbenchmark on an older v5 build shows built-in conditionals are faster.
Safe7.7
How safe is it to depend on?
Claude Opus 5.5: 8.0, likely 7.0 to 9.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.
- npm dependencies: 0 dependencies
- advisories: No advisories recorded
- scorecard score: 4.1 overall; Branch-Protection 0, Security-Policy 0, Code-Review 1
GPT-6.2 Sol: 7.3, likely 6.0 to 8.6
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.
- npm.dependencies, npm.license, advisories: Zero runtime dependencies, MIT licence, and zero recorded OSV advisories.
- scorecard.score, scorecard.checks: Code review 1/10, branch protection, security policy, and fuzzing 0/10.
- github.com/gvergnaud/ts-pattern/releases/tag/v5.9.2: GitHub verifies the release tag’s signature.
- github.com/gvergnaud/ts-pattern/blob/v5.9.2/package.json: Release scripts run tests and a build before npm publication.
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
- npm downloads, 4 weeks
- 39M ×3.2 in a year
- GitHub stars
- 15k
- Commits, 12 months
- 58
- npm version
- 5.9.2 Oct 2026
- Versions, 12 months
- 2
- Advisories, 24 months
- 0 of 0 ever
- OpenSSF Scorecard
- 4.1 out of 10, Oct 2026
- Licence
- MIT
Read on 21 November 2026 from GitHub (gvergnaud/ts-pattern), npm (ts-pattern), OSV and the OpenSSF Scorecard.