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

      Type Parameters

      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.isTrue(Result.expectToBe(okValue, 'should have value') === 'data');

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

      const throwTest = (): void => {
      expectResult(Result.err('boom'));
      };

      assert.throws(throwTest, /missing result/u);

      assert.isTrue(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.

      Parameters

      • message: string

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

      Returns <R extends UnknownResult>(result: R) => UnwrapOk<R>

      The success value if Result.Ok.

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

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

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

      const throwTest = (): void => {
      expectResult(Result.err('boom'));
      };

      assert.throws(throwTest, /missing result/u);

      assert.isTrue(expectResult(Result.ok('value')) === 'value');

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