1.0.6 • Published 3 years ago
tiny-ts-matcher v1.0.6
Install
npm i tiny-ts-matcher
Usage
import { createMatcher } from "tiny-ts-matcher";
const match = createMatcher("status");
type ServerResponse =
| { status: 500; message: string }
| { status: 400; error: string };
const result = match<ServerResponse>()({
500: ({ message }) => message,
400: ({ error }) => error,
_: () => "no match",
})({ status: 500, message: "woops" });
// result: woops