Skip to main content

Built and signed on GitHub Actions

A library exporting the "assertNever" function for exhaustiveness checking.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
10 months ago (0.2.1)

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

assert-never

Utility function for exhaustiveness checking. Use it to get compile-time errors for non-exhaustive switch statements. Example:

usage

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.
}

test

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)

publish

deno publish

License

WTFPL

๐Ÿงจ boom

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

Built and signed on
GitHub Actions
View transparency log

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";