Skip to main content

ok

@ts-rust/std


@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 ParameterDescription

E

The type of the potential error.

Parameters

ParameterTypeDescription

value

void

The void value (typically omitted or undefined).

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 ParameterDescription

T

The type of the value.

E

The type of the potential error.

Parameters

ParameterTypeDescription

value

T

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);