gvergnaud/ts-pattern ? reverse-engineered prompt
Reverse engineered prompt
Build me a TypeScript pattern matching library that makes branching on objects, arrays, tuples, sets, maps, and primitive values feel clean and safe.
I want an API like match(value) with chainable cases such as .with(...), .when(...), .otherwise(...), and .exhaustive(), plus helpers for common patterns like wildcard matching, nested object matching, selecting values out of a match, optional fields, unions, intersections, and exclusion. It should give strong type inference so the matched value is narrowed correctly inside each branch, and it should complain when I forget a possible case.
Please include a few simple examples, like handling API results and reducer style state transitions, and add tests that prove the matching behavior and exhaustiveness checks work. If you need to, look up current TypeScript docs online so the types are solid. Keep the library small and easy to use, with readable error messages and a nice developer experience.
Are you gonna build this?
make sure you review the code using coderabbit