Skip to main content

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@v1.0.1/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@v1.0.1/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.