Skip to main content

Ok<T, E>

Represents a successful result containing a value.

Sinceโ€‹

2.0.0


Type Parametersโ€‹

T: Tโ€‹

The type of the success value

E: Eโ€‹

The type of the error value (unused in Ok)


Implementsโ€‹

  • IResult<T, E>

Constructorsโ€‹

Constructorโ€‹

Creates a new Ok result.

value: T โ€” The success value to wrap
Returns: Ok<T, E>


Propertiesโ€‹

value: Tโ€‹

The success value to wrap


Methodsโ€‹

isOk()โ€‹

Always returns true for Ok instances.

Returns: this is Ok<T, E>โ€‹

true

Implementation of: IResult.isOkโ€‹

isErr()โ€‹

Always returns false for Ok instances. Optimized to return the constant value directly.

Returns: this is Err<T, E>โ€‹

false

Implementation of: IResult.isErrโ€‹

map()โ€‹

Transforms the success value using the provided function.

Type Parametersโ€‹

A: Aโ€‹

The type of the transformed value

f: (t) => A โ€” Function to transform the success value
Returns: Result<A, E> โ€” A new Ok result with the transformed value

Implementation of: IResult.mapโ€‹

mapErr()โ€‹

No-op for Ok instances - the error transformation function is ignored.

Type Parametersโ€‹

U: Uโ€‹

The type of the transformed error (unused)

_f: (e) => U โ€” Error transformation function (ignored)
Returns: Result<T, U> โ€” A new Ok result with the original value

Implementation of: IResult.mapErrโ€‹

andThen()โ€‹

Call Signatureโ€‹

Chains operations by applying the provided function to the success value.

Type Parametersโ€‹
R: R extends Result<unknown, unknown>โ€‹

The type of the Result returned by the function

f: (t) => R โ€” Function that takes the success value and returns a new Result
Returns: Result<InferOkTypes<R>, E | InferErrTypes<R>> โ€” The Result returned by the function

Implementation of: IResult.andThenโ€‹

Call Signatureโ€‹

Chains operations with explicit type parameters.

Type Parametersโ€‹
U: Uโ€‹

The type of the success value in the returned Result

F: Fโ€‹

The type of the error value in the returned Result

f: (t) => Result<U, F> โ€” Function that takes the success value and returns a new Result
Returns: Result<U, E | F> โ€” The Result returned by the function

Implementation of: IResult.andThenโ€‹

unwrapOr()โ€‹

Always returns the success value for Ok instances.

Type Parametersโ€‹

A: Aโ€‹

The type of the default value (unused)

_v: A โ€” Default value (ignored)
Returns: T | A โ€” The success value

Implementation of: IResult.unwrapOrโ€‹

match()โ€‹

Executes the success function with the success value.

Type Parametersโ€‹

A: Aโ€‹

The return type for the success case

B: B = Aโ€‹

The return type for the error case (unused)

ok: (t) => A โ€” Function to execute with the success value
_err: (e) => B โ€” Error function (ignored)
Returns: A | B โ€” The result of executing the success function

Implementation ofโ€‹

IResult.match