Function: assertSuccess()
Asserts that a Result or ResultAsync is a Success and returns it.
If the result is a Failure, throws an error.
Type Param
The type of the success value.
Param
The Result or ResultAsync to assert as a Success.
Throws
If the result is a Failure.
Examples
import { Result } from '@praha/byethrow';
const result: Result.Result<number, string> = Result.succeed(42);
const success = Result.assertSuccess(result);
// success: { type: 'Success', value: 42 }
import { Result } from '@praha/byethrow';
const result: Result.Result<number, string> = Result.fail('error');
Result.assertSuccess(result); // throws Error
import { Result } from '@praha/byethrow';
const result: Result.Result<string, string> = getResult();
const value = Result.pipe(
result,
Result.orElse(() => Result.succeed('fallback')),
Result.assertSuccess,
Result.unwrap(), // Safe unwrap after assertion
);
See
unwrap - Use with assertSuccess
to safely unwrap success values.
Call Signature
assertSuccess<R
>(result
): Promise
<Success
<InferSuccess
<R
>>>
Defined in: functions/assert-success.ts:53
Type Parameters
R
R
extends ResultAsync
<any
, never
>
Parameters
result
R
Returns
Promise
<Success
<InferSuccess
<R
>>>
Call Signature
assertSuccess<R
>(result
): Success
<InferSuccess
<R
>>
Defined in: functions/assert-success.ts:54
Type Parameters
R
R
extends Result
<any
, never
>
Parameters
result
R
Returns
Success
<InferSuccess
<R
>>