Evercatch - v0.10.0
    Preparing search index...

    Function err

    • Creates an error result with a new Error.

      Returns ResultErr<Error>

      A ResultErr containing a new Error.

      const [error, value] = err(); // [Error, null]
      
    • Creates an error result with the given error.

      The error cannot be nullish, since null in the error slot means "this result is ok". Nullish arguments are rejected at compile time, and replaced with a new Error at runtime as a last resort. See NotNullish.

      Any other value is passed through as is, including falsy ones.

      Type Parameters

      • E extends unknown

        The type of the error. Cannot be nullish.

      Parameters

      • error: E

        The error to wrap in an error result.

      Returns ResultErr<E>

      A ResultErr containing the error.

      const [error, value] = err(new Error("Oops")); // [Error: Oops, null]
      
      const [error, value] = err("Oops"); // ["Oops", null]
      
      const [error, value] = err(null); // Type error: null means "no error"