err
@ts-rust/std / Result / err
Function: err()
Call Signature
function err<T>(error): Result<T, void>;
Defined in: packages/std/src/result/result.ts:97
Creates an Err variant of a Result with a void
error.
Wraps undefined
in a CheckedError within an Err,
indicating a failed outcome with no error value for a checked Result.
Type Parameters
Type Parameter | Description |
---|---|
| The type of the potential value. |
Parameters
Parameter | Type | Description |
---|---|---|
|
| The |
Returns
Result
<T
, void
>
A Result containing undefined
as Err.
Example
const x = err<number>();
expect(x.isErr()).toBe(true);
expect(x.unwrapErr().expected).toBeUndefined();
expect(x.unwrapErr().unexpected).toBeUndefined();
Call Signature
function err<T, E>(error): Result<T, E>;
Defined in: packages/std/src/result/result.ts:124
Creates an Err variant of a Result containing the given error.
Wraps the provided error in a CheckedError within an Err, indicating a failed outcome for a checked Result. This function accepts raw error value or CheckedError.
- If called with an error of type
E
, it creates an ExpectedError variant. - If called with a CheckedError, it uses the error as is.
Type Parameters
Type Parameter | Description |
---|---|
| The type of the potential value. |
| The type of the expected error. |
Parameters
Parameter | Type | Description |
---|---|---|
| | | The error to wrap in Err, as a raw |
Returns
Result
<T
, E
>
A Result containing the error as Err.
Example
const oops = new ResultError("err", ResultErrorKind.Unexpected);
const x = err<number, string>("failure");
const y = err<number, string>(oops);
expect(x.isErr()).toBe(true);
expect(x.unwrapErr().expected).toBe("failure");
expect(y.unwrapErr().unexpected).toBe(oops);