@jossmac/lil-libs
    Preparing search index...

    Function assert

    • Asserts that a boolean is true, narrowing the type after the assertion.

      • value: boolean

        Boolean that must be true.

      • Optionalmessage: string

        Optional error message when the assertion fails. Defaults to "Assertion failed".

      assert(isReady); // passes when `isReady` is true
      assert(false); // throws

      If value is false.

    • Asserts that a value is present, narrowing away null and undefined.

      Other falsy values such as 0 and "" pass.

      • T
      • value: T | null | undefined

        Value that must not be null or undefined.

      • Optionalmessage: string

        Optional error message when the assertion fails. Defaults to "Assertion failed".

      function getName(id: number): string | undefined;

      const maybeName = getName(123);
      assert(maybeName, "Name is required");
      const name = maybeName;
      // ^? string

      assert(0); // passes

      If value is null or undefined.