For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/control/unreachable.md.

unreachable

Marks a code path as logically impossible and throws if execution reaches it.

return unreachable('caller pre-validated the input')

Usage

unreachable(message?)

Use unreachable as a runtime assertion for invariants the type system cannot express. Its never return type allows it in any expression position. Reaching the call indicates a bug in the program or invalid data crossing a boundary.

import { unreachable } from 'massaman/control'

function parseDigit(input: string): number {
  const parsed = Number.parseInt(input, 10)

  if (Number.isNaN(parsed)) {
    return unreachable('caller pre-validated the input')
  }

  return parsed
}

Parameters

messagestringoptional

optional context appended to the thrown error message.

Returns

never returns; the function always throws.

never

Throws

An Error with entered unreachable code, optionally followed by message.

See also