tiny-ts-matcher
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

tiny-ts-matcher

License: MIT

type safe replacement for switch statements

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

Package Sidebar

Install

npm i tiny-ts-matcher

Weekly Downloads

2

Version

1.0.6

License

MIT

Unpacked Size

2.55 kB

Total Files

4

Last publish

Collaborators

  • orouz