Utility function for exhaustiveness checking. Use it to get compile-time errors for non-exhaustive switch
statements. Example:
let state: "happy" | "sad" | "mad"; switch(state) { case "happy": return "๐"; case "sad": return "๐ข"; // case "mad" : return "๐ "; default: assertNever(state); // ERROR: // Argument of type '"mad"' is not assignable // to parameter of type 'never'.ts(2345) // // Uncomment the third case to fix the error by making the switch exhaustive. }
deno test Check file:///Volumes/STUFF/CODE/axhxrx-megarepo-jsr-deno-bun-node-hootenanny/libs/ts/assert-never/assertNever.test.ts running 1 test from ./assertNever.test.ts assertNever ... should exist ... ok (0ms) should work ... ok (0ms) assertNever ... ok (1ms) ok | 1 passed (2 steps) | 0 failed (1ms)
deno publish
NOTE: This lib is part of a proof-of-concept test of using JSR.io packages in a monorepo/megarepo context.
The experimental repo is here: https://github.com/axhxrx/axhxrx-megarepo-jsr-deno-bun-node-hootenanny
Add Package
deno add jsr:@axhxrx/assert-never
Import symbol
import * as assert_never from "@axhxrx/assert-never";
---- OR ----
Import directly with a jsr specifier
import * as assert_never from "jsr:@axhxrx/assert-never";
Add Package
npx jsr add @axhxrx/assert-never
Import symbol
import * as assert_never from "@axhxrx/assert-never";
Add Package
yarn dlx jsr add @axhxrx/assert-never
Import symbol
import * as assert_never from "@axhxrx/assert-never";
Add Package
pnpm dlx jsr add @axhxrx/assert-never
Import symbol
import * as assert_never from "@axhxrx/assert-never";
Add Package
bunx jsr add @axhxrx/assert-never
Import symbol
import * as assert_never from "@axhxrx/assert-never";