ts-fortress
    Preparing search index...

    Variable unwrapErrThrowConst

    unwrapErrThrow: <R extends UnknownResult>(
        result: R,
        toStr?: (v: UnwrapOk<R>) => string,
    ) => UnwrapErr<R>

    Unwraps a Result, returning the error value. Throws an error if the Result is Result.Ok.

    This function is used when you expect a Result to be an error and want to extract the error value. If the Result is unexpectedly Ok, it will throw an error with information about the unexpected success value.

    Type Declaration

      • <R extends UnknownResult>(
            result: R,
            toStr?: (v: UnwrapOk<R>) => string,
        ): UnwrapErr<R>
      • Type Parameters

        • R extends UnknownResult

          The UnknownResult type to unwrap.

        Parameters

        • result: R

          The Result to unwrap.

        • OptionaltoStr: (v: UnwrapOk<R>) => string

          An optional function to convert the success value to a string for the error message when the Result is unexpectedly Ok. Defaults to String.

        Returns UnwrapErr<R>

        The error value if Result.Err.

    const errResult = Result.err(new Error('broken'));

    const okResult = Result.ok('value');

    assert.isTrue(Result.unwrapErrThrow(errResult).message === 'broken');

    assert.throws(() => Result.unwrapErrThrow(okResult), /Expected Err/u);

    Error with message "Expected Err but got Ok: {value}" if the Result is Result.Ok.