ts-data-forge
    Preparing search index...
    • Unwraps a Result, returning the success value or undefined if it's an error.

      This function provides a safe way to extract success values from Results without throwing exceptions. It has overloaded behavior based on the type:

      • For Result.Ok<T>: Always returns T (guaranteed by type system)
      • For general Result<T, E>: Returns T | undefined

      Type Parameters

      • R extends Readonly<{ value: unknown }>

        The Result.Base type to unwrap.

      Parameters

      • result: R

        The Result to unwrap.

      Returns UnwrapOk<R>

      The success value if Result.Ok, otherwise undefined.

      const okResult = Result.ok(42);
      const errResult = Result.err('oops');

      // Result.unwrapOk returns the value for Ok results

      assert(Result.unwrapOk(okResult) === 42);

      // Result.unwrapOk returns undefined for Err results
      // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
      assert(Result.unwrapOk(errResult) === undefined);
    • Unwraps a Result, returning the success value or undefined if it's an error.

      This function provides a safe way to extract success values from Results without throwing exceptions. It has overloaded behavior based on the type:

      • For Result.Ok<T>: Always returns T (guaranteed by type system)
      • For general Result<T, E>: Returns T | undefined

      Type Parameters

      • R extends Result.Base

        The Result.Base type to unwrap.

      Parameters

      • result: R

        The Result to unwrap.

      Returns UnwrapOk<R> | undefined

      The success value if Result.Ok, otherwise undefined.

      const okResult = Result.ok(42);
      const errResult = Result.err('oops');

      // Result.unwrapOk returns the value for Ok results

      assert(Result.unwrapOk(okResult) === 42);

      // Result.unwrapOk returns undefined for Err results
      // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
      assert(Result.unwrapOk(errResult) === undefined);