@metreeca/core - v0.9.1
    Preparing search index...

    Function error

    • Throws an error in expression contexts.

      Enables error throwing in functional style code where expressions are required, such as ternary operators, arrow functions, or array methods.

      Type Parameters

      • V

        The expected return type for type compatibility (never actually returns)

      Parameters

      • error: string | Error

        The error message string or Error instance to throw

      Returns V

      Never returns (always throws)

      The provided error or a new Error with the provided message

      // Use in ternary operator
      const value = isValid(input) ? input : error("Invalid input");

      // Use in arrow function
      const getRequired = (key: string) => map.get(key) ?? error(`Missing key: ${key}`);

      // Use in array method
      const items = data.map(item => item.value ?? error("Missing value"));