# ts\-pattern

[BASE product page](<https://base.akulich.dev/en/library/ts-pattern/>) · [Resource](<https://github.com/gvergnaud/ts-pattern>)

ID: ts\-pattern · Language: en
Schema version: 1 · Data version: cbbe7123b47a5ae80983

This is editorial data. An unknown field neither confirms nor rules out a capability.
dataVersion is a dataset fingerprint, not evidence of a recent fact check.

TypeScript pattern matching with exhaustive checking and type inference: it expresses branching over complex data structures through clear cases\.

## Type

Backend / API library

## Entry type

library

## Separate catalog

No

## [Access conditions](<https://base.akulich.dev/en/library/ts-pattern/#resource-access>)

free

## [What you can use for free](<https://base.akulich.dev/en/library/ts-pattern/#resource-access>)

Code and local use under MIT\.

## [Paid features and costs](<https://base.akulich.dev/en/library/ts-pattern/#resource-access>)

Computing resources, self\-hosting, and external services are paid for separately if used\.

## [Access and limitations](<https://base.akulich.dev/en/library/ts-pattern/#resource-access>)

Code and local use under MIT\. Computing resources, self\-hosting, and external services are paid for separately if used\.

## [Use cases](<https://base.akulich.dev/en/library/ts-pattern/#resource-tasks>)

- Express exhaustive branching over typed data
- Connect pattern branches to handling every data variant

## Category IDs

- backend

## Subcategory IDs

- backend\.api

## Tags

- ts\-pattern
- API
- Development

## Also known as

- gvergnaud/ts\-pattern
- ts\-pattern
- pattern\-matching\-library

## [Selection purpose](<https://base.akulich.dev/en/library/ts-pattern/#resource-selection>)

Express exhaustive branching over typed data

## [Choose this when](<https://base.akulich.dev/en/library/ts-pattern/#resource-selection>)

- Express exhaustive branching over typed data
- Connect pattern branches to handling every data variant

## [Requirements](<https://base.akulich.dev/en/library/ts-pattern/#resource-selection>)

- 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](<https://base.akulich.dev/en/library/ts-pattern/#resource-selection>)

- 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\.

## [Questions before use](<https://base.akulich.dev/en/library/ts-pattern/#resource-faq>)

### What can you use for free in ts\-pattern?

Code and local use under MIT\.

### What additional costs might arise with ts\-pattern?

Computing resources, self\-hosting, and external services are paid for separately if used\.

### What terms of use matter for ts\-pattern?

MIT for the code; dependencies have separate licenses\.

### How do you get started with ts\-pattern?

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\.

### How does TS\-Pattern help process nested data?

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\.

## Sources for the selection guide

- [https://github\.com/gvergnaud/ts\-pattern](<https://github.com/gvergnaud/ts-pattern>)
- [https://raw\.githubusercontent\.com/gvergnaud/ts\-pattern/HEAD/README\.md](<https://raw.githubusercontent.com/gvergnaud/ts-pattern/HEAD/README.md>)
- [https://raw\.githubusercontent\.com/gvergnaud/ts\-pattern/HEAD/LICENSE](<https://raw.githubusercontent.com/gvergnaud/ts-pattern/HEAD/LICENSE>)
- [https://www\.open\-source\-tools\.com/](<https://www.open-source-tools.com/>)

## [Possible workflow](<https://base.akulich.dev/en/library/ts-pattern/#resource-scenario>)

Express exhaustive branching over typed data\.

A possible workflow; this is not a report of hands-on testing.

## Before you start

- A data contract or HTTP workflow\.
- A project with a supported runtime\.

## Steps

1. Define the state union and expected matching cases\.
2. Connect pattern branches to handling every data variant\.
3. Add error handling and an integration check of the result\.

## Check your result

- Invalid and missing data are handled predictably\.
- Types and the actual response agree; errors are not hidden\.

## [License](<https://base.akulich.dev/en/library/ts-pattern/#resource-license>)

MIT for the code; dependencies have separate licenses\.

## License explanations for the specified scope

### MIT — permissive license

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\.

[License terms](<https://opensource.org/license/mit>)

## [Sources](<https://base.akulich.dev/en/library/ts-pattern/#resource-sources>)

- [Official source](<https://github.com/gvergnaud/ts-pattern>)
- [Official source](<https://raw.githubusercontent.com/gvergnaud/ts-pattern/HEAD/README.md>)
- [License](<https://raw.githubusercontent.com/gvergnaud/ts-pattern/HEAD/LICENSE>)
- [Catalog / discovery source](<https://www.open-source-tools.com/>)

## Editorial review date

2026\-10\-06

## Editorial review scope

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\.

Dates refer to the stated editorial review, not hands-on testing, a product update, or a recent review of all sources.
