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
3 months ago (0.2.1)
function assertNever
assertNever(x?: never): never

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

Parameters

optional
x: never

Return Type

never

Add Package

deno add jsr:@axhxrx/assert-never

Import symbol

import { assertNever } from "@axhxrx/assert-never";

---- OR ----

Import directly with a jsr specifier

import { assertNever } from "jsr:@axhxrx/assert-never";

Add Package

npx jsr add @axhxrx/assert-never

Import symbol

import { assertNever } from "@axhxrx/assert-never";

Add Package

yarn dlx jsr add @axhxrx/assert-never

Import symbol

import { assertNever } from "@axhxrx/assert-never";

Add Package

pnpm dlx jsr add @axhxrx/assert-never

Import symbol

import { assertNever } from "@axhxrx/assert-never";

Add Package

bunx jsr add @axhxrx/assert-never

Import symbol

import { assertNever } from "@axhxrx/assert-never";