ok
@ts-rust/std / Result / ok
Function: ok()
Call Signature
function ok<E>(value): Result<void, E>;
Defined in: packages/std/src/result/result.ts:53
Creates an Ok variant of a Result with a void
value.
Wraps undefined
in an Ok, indicating a successful outcome with
no value (void
) for a checked Result.
Type Parameters
Type Parameter | Description |
---|---|
| The type of the potential error. |
Parameters
Parameter | Type | Description |
---|---|---|
|
| The |
Returns
Result
<void
, E
>
A Result containing undefined
as Ok.
Example
const x = ok<string>();
expect(x.isOk()).toBe(true);
expect(x.unwrap()).toBeUndefined();
Call Signature
function ok<T, E>(value): Result<T, E>;
Defined in: packages/std/src/result/result.ts:73
Creates an Ok variant of a Result containing the given value.
Wraps the provided value in an Ok, indicating a successful outcome for a checked Result.
Type Parameters
Type Parameter | Description |
---|---|
| The type of the value. |
| The type of the potential error. |
Parameters
Parameter | Type | Description |
---|---|---|
|
| The value to wrap in Ok. |
Returns
Result
<T
, E
>
A Result containing the value as Ok.
Example
const x = ok<number, string>(42);
expect(x.isOk()).toBe(true);
expect(x.unwrap()).toBe(42);