Skip to content

Variable: ok()

readonly ok: <T, E>(value) => Ok<T, E>

Defined in: core/factories.ts:47

Creates a success Result containing a value.

Use when you have a valid value and want to encapsulate it in a Result to work with the fluent API or maintain consistency in function returns.

Type Parameters

T

T

Success value type

E

E = never

Error type (never used in Ok, but needed for typing)

Parameters

value

T

Success value to encapsulate

Returns

Ok<T, E>

An Ok Result containing the value

Examples

ts
// Basic usage
const result = Result.ok(42)
ts
// In functions
function divide(a: number, b: number): Result<number, string> {
  if (b === 0) return Result.err('division by zero')
  return Result.ok(a / b)
}
ts
// With complex types
interface User { id: number; name: string }
const user: User = { id: 1, name: 'John' }
const result = Result.ok(user)