IF Commons GitHub

absurd

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0001-core FR-001

Exhaustive matching: a switch on a union's kind ends with default: return absurd(value), so that an alternative left out does not compile (0001-core FR-001). One name, absurd, for what erga called absurd and the machine setup assertNever.

import { absurd } from "./absurd.ts";
type Shape = { readonly kind: "circle"; readonly r: number } | { readonly kind: "square"; readonly side: number };
function area(s: Shape): number {
  switch (s.kind) {
    case "circle": return Math.PI * s.r ** 2;
    case "square": return s.side ** 2;
    default: return absurd(s);
  }
}

Source: commons/core/src/absurd.ts

1 of 1 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

absurdfunction
function absurd(value: never): never

The end of an exhaustive switch: its argument has the type never only when every alternative was handled. It throws if reached.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.