Asserts given conditions.

Type signature

(
  condition: boolean,
  callbackOrMessage:
    | {
        (): void;
      }
    | string
) => void

Examples

assert(true === false);
// ⇒ TypeError("Assertion failed!")
Try in REPL

Questions

  • How to assert a condition?
  • How to throw when a condition is not satisfied?

TypeScript sourceJavaScript source