Skip to main content

Make tolerable a poor man's version of exhaustive pattern-matching, in TypeScript

Works with
It is unknown whether this package works with Bun
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
This package works with Browsers
JSR Score
100%
Published
3 months ago

exhaustive is a function to help statically check that you explicitly handle all possible values.

See its documentation for a longer explanation. TypeScript's never type is the novel thing that makes it work.

We could copy & paste the function definition into a "utils" file in each project, but why not define it centrally and reuse it? That's why it's been put on this module registry:

import exhaustive from "jsr:@duncan/exhaustive"

Add Package

deno add @duncan/exhaustive

Import symbol

import * as mod from "@duncan/exhaustive";

Add Package

npx jsr add @duncan/exhaustive

Import symbol

import * as mod from "@duncan/exhaustive";

Add Package

yarn dlx jsr add @duncan/exhaustive

Import symbol

import * as mod from "@duncan/exhaustive";

Add Package

pnpm dlx jsr add @duncan/exhaustive

Import symbol

import * as mod from "@duncan/exhaustive";

Add Package

bunx jsr add @duncan/exhaustive

Import symbol

import * as mod from "@duncan/exhaustive";