Result.ok()
Creates a successful result containing a value.Signatures
Parameters
A
The success value to wrap. If omitted, creates
Ok<void, never> for side-effectful operations.Returns
Ok<A, E>
An Ok instance containing the value
Examples
With a Value
Without a Value (void)
With Explicit Error Type
Result.err()
Creates an error result containing an error value.Signature
Parameters
E
required
The error value to wrap
Returns
Err<T, E>
An Err instance containing the error
Examples
With a String Error
With a Custom Error Class
With Explicit Success Type
Understanding Phantom Types
Bothok() and err() support phantom type parameters:
- Type unification in Result unions
- Proper inference in
Result.gen()composition - Type safety across multiple operations
Example: Why Phantom Types Matter
Result<number, string> type.