Skip to main content

🦕. A type-check utility function to indicating that the code is unreachable

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
2 months ago (1.0.1)

unreachable

jsr denoland deno doc Test

A type-check utility function to indicating that the code is unreachable.

Usage

For example, the following code passed type checking.

import { unreachable } from "https://deno.land/x/unreachable@$MODULE_VERSION/mod.ts";

type Animal = "dog" | "cat";

function say(animal: Animal): void {
  switch (animal) {
    case "dog":
      console.log("dog");
      break;
    case "cat":
      console.log("dog");
      break;
    default:
      unreachable(animal);
  }
}
say("dog");

But the following code because a case for "bird" is missing.

import { unreachable } from "https://deno.land/x/unreachable@$MODULE_VERSION/mod.ts";

type Animal = "dog" | "cat" | "bird";

function say(animal: Animal): void {
  switch (animal) {
    case "dog":
      console.log("dog");
      break;
    case "cat":
      console.log("dog");
      break;
    default:
      unreachable(animal);
  }
}
say("dog");

License

The code follows MIT license written in LICENSE. Contributors need to agree that any modifications sent in this repository follow the license.

Built and signed on
GitHub Actions
View transparency log

Add Package

deno add @lambdalisue/unreachable

Import symbol

import * as mod from "@lambdalisue/unreachable";

Add Package

npx jsr add @lambdalisue/unreachable

Import symbol

import * as mod from "@lambdalisue/unreachable";

Add Package

yarn dlx jsr add @lambdalisue/unreachable

Import symbol

import * as mod from "@lambdalisue/unreachable";

Add Package

pnpm dlx jsr add @lambdalisue/unreachable

Import symbol

import * as mod from "@lambdalisue/unreachable";

Add Package

bunx jsr add @lambdalisue/unreachable

Import symbol

import * as mod from "@lambdalisue/unreachable";