ts-pattern is an open-source TypeScript library that introduces expressive, type-safe pattern matching for handling complex conditional logic. It allows developers to replace lengthy switch statements and nested conditionals with concise declarative expressions. The library supports matching primitive values, nested objects, arrays, tuples, maps, and sets. Its advanced TypeScript inference automatically narrows types based on matched patterns, reducing the need for manual assertions. Exhaustiveness checking detects unhandled cases during compilation and helps prevent unexpected application behavior. Developers can create conditional patterns using predicates, unions, intersections, exclusions, and wildcard matchers. It also supports extracting matched values and validating data structures. With a small bundle footprint, ts-pattern integrates into existing TypeScript applications without requiring additional runtime infrastructure.

Features

  • Type-Safe Declarative Pattern Matching
  • Compile-Time Exhaustiveness Checking
  • Nested Object and Array Matching
  • Advanced Type Inference and Narrowing
  • Wildcard, Predicate, and Union Patterns
  • Data Validation and Value Extraction

Project Samples

Project Activity

See All Activity >

Categories

Libraries

License

MIT License

Follow TS-Pattern

TS-Pattern Web Site

Other Useful Business Software
Paessler: Easy to Use With Enterprise Power. Free Trial Icon
Paessler: Easy to Use With Enterprise Power. Free Trial

A low-code dashboard makes monitoring intuitive for any admin, while scripting and custom sensors give experts full control.

You shouldn't have to choose between a monitoring tool that's easy to use and one that's powerful enough for a complex environment. PRTG's low-code interface lets any admin build dashboards, set alerts and monitor devices without scripting, while custom sensors and full API access are there when your team needs deeper control. One platform, no compromise. Download a free 30-day trial now.
Get Free Download
Rate This Project
Login To Rate This Project

User Reviews

Be the first to post a review of TS-Pattern!

Additional Project Details

Programming Language

TypeScript

Related Categories

TypeScript Libraries

Registered

3 days ago