Skip to main content
Module

x/unknownutil/util.ts>setAssertMessageFactory

🦕 A lightweight utility pack for handling unknown type
Go to Latest
function setAssertMessageFactory
import { setAssertMessageFactory } from "https://deno.land/x/unknownutil@v3.18.0/util.ts";

Sets the factory function used to generate assertion error messages.

Examples

Example 1

import { is, setAssertMessageFactory } from "@core/unknownutil";

setAssertMessageFactory((x, pred) => {
  if (pred === is.String) {
    return `Expected a string, got ${typeof x}`;
  } else if (pred === is.Number) {
    return `Expected a number, got ${typeof x}`;
  } else if (pred === is.Boolean) {
    return `Expected a boolean, got ${typeof x}`;
  } else {
    return `Expected a value that satisfies the predicate, got ${typeof x}`;
  }
});

Parameters

The factory function.