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