Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/orouz/tiny-ts-matcher
type safe replacement for switch statements
https://github.com/orouz/tiny-ts-matcher
pattern-matching typescript
Last synced: 1 day ago
JSON representation
type safe replacement for switch statements
- Host: GitHub
- URL: https://github.com/orouz/tiny-ts-matcher
- Owner: orouz
- Created: 2021-02-12T23:49:09.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-08T19:29:31.000Z (almost 3 years ago)
- Last Synced: 2024-03-24T18:01:49.475Z (8 months ago)
- Topics: pattern-matching, typescript
- Language: TypeScript
- Homepage:
- Size: 273 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
☔tiny-ts-matcher
type safe replacement for switch statements
## **Install**
`npm i tiny-ts-matcher`
## **Usage**
```typescript
import { createMatcher } from "tiny-ts-matcher";const match = createMatcher("status");
type ServerResponse =
| { status: 500; message: string }
| { status: 400; error: string };const result = match()({
500: ({ message }) => message,
400: ({ error }) => error,
_: () => "no match",
})({ status: 500, message: "woops" });// result: woops
```