ts-data-forge
    Preparing search index...
    • Unwraps a Result, returning the error value or undefined if it is Result.Ok.

      This provides a safe way to extract error values from Results without throwing exceptions. Useful for error handling patterns where you want to check for specific error conditions.

      Type Parameters

      • R extends Result.Base

        The Result.Base type to unwrap.

      Parameters

      • result: R

        The Result to unwrap.

      Returns UnwrapErr<R> | undefined

      The error value if Result.Err, otherwise undefined.

      const okResult = Result.ok('data');
      const errResult = Result.err('problem');

      // Result.unwrapErr returns undefined for Ok results
      // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
      assert(Result.unwrapErr(okResult) === undefined);

      // Result.unwrapErr returns the error value for Err results

      assert(Result.unwrapErr(errResult) === 'problem');