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
Train ML Models With SQL You Already Know Icon
Train ML Models With SQL You Already Know

BigQuery automates data prep, analysis, and predictions with built-in AI assistance.

Build and deploy ML models using familiar SQL. Automate data prep with built-in Gemini. Query 1 TB and store 10 GB free monthly.
Start Free
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

5 days ago