{"schemaVersion":1,"id":"ts-pattern","name":"ts-pattern","locale":"en","canonicalUrl":"https://base.akulich.dev/en/library/ts-pattern/","officialUrl":"https://github.com/gvergnaud/ts-pattern","isCatalog":false,"description":"TypeScript pattern matching with exhaustive checking and type inference: it expresses branching over complex data structures through clear cases.","tasks":["Express exhaustive branching over typed data","Connect pattern branches to handling every data variant"],"categoryIds":["backend"],"subcategoryIds":["backend.api"],"tags":["ts-pattern","API","Development"],"aliases":["gvergnaud/ts-pattern","ts-pattern","pattern-matching-library"],"platforms":[],"stack":[],"compatibility":null,"pricing":"free","freeUsage":"Code and local use under MIT.","paidUsage":"Computing resources, self-hosting, and external services are paid for separately if used.","license":"MIT for the code; dependencies have separate licenses.","selectionGuide":{"purpose":"Express exhaustive branching over typed data","chooseWhen":["Express exhaustive branching over typed data","Connect pattern branches to handling every data variant"],"considerInstead":[],"requirements":["The README shows npm install ts-pattern; use named P.select for multiple extracted fields, since a pattern can contain only one anonymous selection."],"limitations":["Costs and limits of free use: Computing resources, self-hosting, and external services are paid for separately if used.","Terms of use: MIT for the code; dependencies have separate licenses.","Completeness checking adds compiler work. With incorrect types, an unexpected value can still reach .exhaustive() and trigger a runtime error; a custom handler can be provided."],"faq":[{"question":"What can you use for free in ts-pattern?","answer":"Code and local use under MIT."},{"question":"What additional costs might arise with ts-pattern?","answer":"Computing resources, self-hosting, and external services are paid for separately if used."},{"question":"What terms of use matter for ts-pattern?","answer":"MIT for the code; dependencies have separate licenses."},{"question":"How do you get started with ts-pattern?","answer":"Define the state union and expected matching cases. Connect pattern branches to handling every data variant. Add error handling and an integration check of the result."},{"question":"How does TS-Pattern help process nested data?","answer":"match checks .with() branches against value structure; P.select extracts selected nested parts into a handler, and P.when adds a conditional check. .exhaustive() enables compile-time branching completeness checks."}],"related":[],"sources":["https://github.com/gvergnaud/ts-pattern","https://raw.githubusercontent.com/gvergnaud/ts-pattern/HEAD/README.md","https://raw.githubusercontent.com/gvergnaud/ts-pattern/HEAD/LICENSE","https://www.open-source-tools.com/"]},"selectionCheckedAt":null,"applicationGuide":{"goal":"Express exhaustive branching over typed data.","inputs":["A data contract or HTTP workflow.","A project with a supported runtime."],"steps":["Define the state union and expected matching cases.","Connect pattern branches to handling every data variant.","Add error handling and an integration check of the result."],"checks":["Invalid and missing data are handled predictably.","Types and the actual response agree; errors are not hidden."]},"sources":["https://github.com/gvergnaud/ts-pattern","https://raw.githubusercontent.com/gvergnaud/ts-pattern/HEAD/README.md","https://raw.githubusercontent.com/gvergnaud/ts-pattern/HEAD/LICENSE","https://www.open-source-tools.com/"],"checkedAt":"2026-10-06","reviewScope":"The purpose, current repository license, and separate terms for code, services, and models have been reviewed. The product was not run, and no security audit was performed.","relatedIds":[],"dataVersion":"cbbe7123b47a5ae80983","type":"Backend / API library","kind":"library","pricingNote":"Code and local use under MIT. Computing resources, self-hosting, and external services are paid for separately if used.","notes":null,"labeledSources":[{"url":"https://github.com/gvergnaud/ts-pattern","label":"Official source"},{"url":"https://raw.githubusercontent.com/gvergnaud/ts-pattern/HEAD/README.md","label":"Official source"},{"url":"https://raw.githubusercontent.com/gvergnaud/ts-pattern/HEAD/LICENSE","label":"License"},{"url":"https://www.open-source-tools.com/","label":"Catalog / discovery source"}],"licenseGuides":[{"id":"mit","title":"MIT — permissive license","scope":null,"summary":"You can use, modify, distribute, and sell the code, including in a closed-source commercial product. When sharing copies or substantial portions of the code, retain the license text and copyright notice. You do not need to open-source your entire project; the author provides no warranties.","url":"https://opensource.org/license/mit"}],"entryIds":[],"composition":null}