ts-data-forge
    Preparing search index...
    • Unwraps a Result, returning the success value or throwing an error with the provided message.

      Type Parameters

      • R extends Result.Base

        The Result.Base type to unwrap.

      Parameters

      • result: R

        The Result to unwrap.

      • message: string

        The error message to throw if the Result is Result.Err.

      Returns UnwrapOk<R>

      The success value if Result.Ok.

      const okValue = Result.ok('data');

      assert(Result.expectToBe(okValue, 'should have value') === 'data');

      const expectResult = Result.expectToBe<string>('missing result');

      assert.throws(() => expectResult(Result.err('boom')), /missing result/u);
      assert(expectResult(Result.ok('value')) === 'value');

      Error with the provided message if the Result is Result.Err.

    • Unwraps a Result, returning the success value or throwing an error with the provided message.

      Type Parameters

      • S

      Parameters

      • message: string

        The error message to throw if the Result is Result.Err.

      Returns <E>(result: Result<S, E>) => S

      The success value if Result.Ok.

      const okValue = Result.ok('data');

      assert(Result.expectToBe(okValue, 'should have value') === 'data');

      const expectResult = Result.expectToBe<string>('missing result');

      assert.throws(() => expectResult(Result.err('boom')), /missing result/u);
      assert(expectResult(Result.ok('value')) === 'value');

      Error with the provided message if the Result is Result.Err.