Skip to main content

Function: isOk()

isOk<T, E>(result): result is Ok<T>

Defined in: result/guards/index.ts:20

Type guard to check if a Result is Ok.

Narrows the type to Ok, allowing safe access to the value property.

Type Parameters

T

T

E

E

Parameters

result

Result<T, E>

The Result to check

Returns

result is Ok<T>

True if the Result is Ok, false otherwise

Example

const result: Result<number, string> = ok(42)

if (isOk(result)) {
console.log(result.value) // TypeScript knows this is safe
}