tiny-ts-matcher
v1.0.6
Published
type safe replacement for switch statements
Downloads
3
Readme
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