ts-fortress
    Preparing search index...

    Variable unwrapThrowConst

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

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

    This is useful when you're confident that a Result should contain a success value and want to treat errors as exceptional conditions. The error message will be constructed from the error value using the provided string conversion function.

    Type Declaration

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

        • R extends UnknownResult

          The UnknownResult type to unwrap.

        Parameters

        • result: R

          The Result to unwrap.

        • OptionaltoStr: (e: UnwrapErr<R>) => string

          An optional function to convert the error value to a string for the error message. Defaults to String.

        Returns UnwrapOk<R>

        The success value if Result.Ok.

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

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

    assert.isTrue(Result.unwrapThrow(okResult) === 'data');

    assert.throws(() => Result.unwrapThrow(errResult), Error, 'fail');

    Error with the stringified error value if the Result is Result.Err.