{"slug": "ts-pattern", "name": "ts-pattern", "category": "dev-libs", "category_name": "Libraries and frameworks", "description": "", "recommenders": 3, "commenters": 4, "warners": 1, "score": 1.797, "rising": 1.67, "first": "2025-11-23", "latest": "2026-10-18", "why": "I would highly recommend the ts-pattern [1] library if you find yourself wanting exhaustive switch statements!", "why_is_quote": true, "has_verdict": false, "sentiment": {"recommend": 3, "neutral": 0, "compare": 0, "warn": 1}, "spark": [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], "listed": true, "loved": [], "caveat": "", "short_quote": "I would highly recommend the ts-pattern [1] library if you find yourself wanting exhaustive switch statements!", "kind": "", "icon": false, "domain": null, "github_repo": "github.com/gvergnaud/ts-pattern", "official_url": "https://github.com/gvergnaud/ts-pattern", "pricing": "", "aliases": ["ts-pattern"], "verdict": null, "praise": [{"label": "", "summary": "", "quotes": [{"id": 802306240, "item_id": 50144140, "url": "https://news.ycombinator.com/item?id=50144140", "by": "shepherdjerred", "date": "2026-10-18", "stance": "recommend", "quote": "you can do exhaustive pattern matching in TypeScript! https://github.com/gvergnaud/ts-pattern", "excerpt": "I love how far Java has come. I still prefer TypeScript since I do a lot of frontend work and prefer to use the same language across the stack. With the said, you can do exhaustive pattern matching in TypeScript! https://github.com/gvergnaud/ts-pattern", "context": "frontend developer preferring one language across the stack", "use_case": "exhaustive pattern matching in TypeScript", "switched_from": "", "story": "Java sealed classes and exhaustive pattern matching"}, {"id": 736346736, "item_id": 46021671, "url": "https://news.ycombinator.com/item?id=46021671", "by": "your_fin", "date": "2025-11-23", "stance": "recommend", "quote": "I would highly recommend the ts-pattern [1] library if you find yourself wanting exhaustive switch statements!", "excerpt": "I would highly recommend the ts-pattern [1] library if you find yourself wanting exhaustive switch statements! The syntax is a bit noiser than case statements in simple cases, but I find it less awkward for exhaustive pattern matching and much harder to shoot yourself in the foot with. Once you get familiar with it, it can trim down a /lot/ of more complicated logic too. It also makes match expressions an expression ", "context": "", "use_case": "exhaustive pattern matching in TypeScript", "switched_from": "", "story": "`satisfies` is my favorite TypeScript keyword (2024)"}]}], "caveats": [{"label": "", "summary": "", "quotes": [{"id": 802321920, "item_id": 50145120, "url": "https://news.ycombinator.com/item?id=50145120", "by": "wk_end", "date": "2026-10-18", "stance": "warn", "quote": "I don't think it's worth the external dependency and added complexity.", "excerpt": "You don't need a library for this; the idiomatic approach is to lean on TypeScript's narrowing and native control flow (ifs and switches, or maybe IIFEs), along with (maybe) the never type to enforce exhaustiveness. https://www.typescriptlang.org/play/?jsx=4#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wG4AocmATzCTgBEUYU4BecuOAHzgG84NOgC4CMJAA8YZOGggA7cYtEBnGFGDyA5nAC+nHv0G0ko-KC0yVUNKvWaduilROIkKgK4AbeBy68BIVMCCABrGQATZhR", "context": "", "use_case": "", "switched_from": "", "story": "Java sealed classes and exhaustive pattern matching"}]}], "who": [{"by": "shepherdjerred", "context": "frontend developer preferring one language across the stack", "url": "https://news.ycombinator.com/item?id=50144140", "date": "2026-10-18"}], "tags": [], "use_cases": ["exhaustive pattern matching in typescript"], "compared": [], "makers": [], "threads": [{"url": "https://news.ycombinator.com/item?id=50141579", "title": "Java sealed classes and exhaustive pattern matching", "mentions": 3}, {"url": "https://news.ycombinator.com/item?id=45968310", "title": "`satisfies` is my favorite TypeScript keyword (2024)", "mentions": 1}], "sentiment_by_month": {"2025-11": {"recommend": 1}, "2025-12": {}, "2026-01": {}, "2026-02": {}, "2026-03": {}, "2026-04": {}, "2026-05": {}, "2026-06": {}, "2026-07": {}, "2026-08": {}, "2026-09": {}, "2026-10": {"recommend": 2, "warn": 1}}, "quotes": [{"id": 802322880, "item_id": 50145180, "url": "https://news.ycombinator.com/item?id=50145180", "by": "ngruhn", "date": "2026-10-18", "stance": "recommend", "quote": "", "excerpt": "Isn't that overkill? You can check exhaustiveness with a trivial little helper: function exhaustive(witness: never): never { return witness } https://www.typescriptlang.org/play/?#code/FAFwngDgpgBAKgZQBYEsBOIEoF6wLwwBEAGgDKEwA+R5VRAshdYQocMAGYCuAdgMYgUAex4woADyQBDLgGdBANygAKAO4oQPKLNkAuGFqVoAlPsNQ0MAN7AYMNFBBc0o9Zu2zgAX3bd+gkRgQWVQMUigeAHMQJGVZHCh9RFDMBNMDLgBbACMLa1sYWTc+JBg4tPy7Oz4pWVgAcgR6-QcnFxgANgBOAG4C6tqG+mb7R2", "context": "", "use_case": "", "switched_from": "", "story": "Java sealed classes and exhaustive pattern matching"}, {"id": 802321920, "item_id": 50145120, "url": "https://news.ycombinator.com/item?id=50145120", "by": "wk_end", "date": "2026-10-18", "stance": "warn", "quote": "I don't think it's worth the external dependency and added complexity.", "excerpt": "You don't need a library for this; the idiomatic approach is to lean on TypeScript's narrowing and native control flow (ifs and switches, or maybe IIFEs), along with (maybe) the never type to enforce exhaustiveness. https://www.typescriptlang.org/play/?jsx=4#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wG4AocmATzCTgBEUYU4BecuOAHzgG84NOgC4CMJAA8YZOGggA7cYtEBnGFGDyA5nAC+nHv0G0ko-KC0yVUNKvWaduilROIkKgK4AbeBy68BIVMCCABrGQATZhR", "context": "", "use_case": "", "switched_from": "", "story": "Java sealed classes and exhaustive pattern matching"}, {"id": 802306240, "item_id": 50144140, "url": "https://news.ycombinator.com/item?id=50144140", "by": "shepherdjerred", "date": "2026-10-18", "stance": "recommend", "quote": "you can do exhaustive pattern matching in TypeScript! https://github.com/gvergnaud/ts-pattern", "excerpt": "I love how far Java has come. I still prefer TypeScript since I do a lot of frontend work and prefer to use the same language across the stack. With the said, you can do exhaustive pattern matching in TypeScript! https://github.com/gvergnaud/ts-pattern", "context": "frontend developer preferring one language across the stack", "use_case": "exhaustive pattern matching in TypeScript", "switched_from": "", "story": "Java sealed classes and exhaustive pattern matching"}, {"id": 736346736, "item_id": 46021671, "url": "https://news.ycombinator.com/item?id=46021671", "by": "your_fin", "date": "2025-11-23", "stance": "recommend", "quote": "I would highly recommend the ts-pattern [1] library if you find yourself wanting exhaustive switch statements!", "excerpt": "I would highly recommend the ts-pattern [1] library if you find yourself wanting exhaustive switch statements! The syntax is a bit noiser than case statements in simple cases, but I find it less awkward for exhaustive pattern matching and much harder to shoot yourself in the foot with. Once you get familiar with it, it can trim down a /lot/ of more complicated logic too. It also makes match expressions an expression ", "context": "", "use_case": "exhaustive pattern matching in TypeScript", "switched_from": "", "story": "`satisfies` is my favorite TypeScript keyword (2024)"}]}