This library, `typescript-pattern-matching`, offers functional-style pattern matching capabilities for TypeScript, addressing the absence of native `match` or `case` keywords found in languages like F# or Haskell. It enables developers to implement sophisticated conditional logic by comparing data against various patterns, including value, record, wildcard, and negated patterns, with robust type inference. Version 1.0.1 is the latest release, but the project has seen no updates in over six years (last published December 2019). While it provides a basic implementation for structured pattern matching, its development has ceased, leading to a state of abandonment. More actively maintained and feature-rich alternatives have emerged in the TypeScript ecosystem. It requires TypeScript 3.7.3 or higher to function correctly.
npm install typescript-pattern-matchingVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic pattern matching on a discriminated union (`Option<T>`) and using `.otherwise()` for a default case.
Consider migrating to more actively maintained pattern matching libraries like `ts-pattern` for better compatibility, features, and continued support.
Ensure your project uses TypeScript version 3.7.3 or newer in `tsconfig.json`.
Always include an `.otherwise()` clause or thoroughly review your patterns to ensure all possible input shapes are handled.
Ensure that every pattern matching chain explicitly ends with `.run()` or `.otherwise()`.
Review the type definitions of your input and patterns. Explicitly cast types if necessary, or simplify patterns to ensure clearer type inference. For complex types, consider using type predicates in custom `when` clauses.
No dependency data recorded yet.