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