Skip to main content
Module

x/unreachable/mod.ts>unreachable

🦕. A type-check utility function to indicating that the code is unreachable
Latest
function unreachable
import { unreachable } from "https://deno.land/x/unreachable@v1.0.1/mod.ts";

Function indicating that this part is unreachable.

For example, the following code passed type checking.

import { unreachable } from "./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 "./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");

Parameters

...args: never[]

Returns

never