A type-safe way to handle success and error cases. The Result type is used throughout the library to handle decoding results.
The type of the successful value
Creates a new Ok instance containing a successful value.
The successful value
Readonly
Type guard to check if this Result is an Ok. Always returns true for Ok instances.
true for Ok instances
const result: Result<number> = ok(5);if (result.isOk()) { // TypeScript knows result.value exists here console.log(result.value);} Copy
const result: Result<number> = ok(5);if (result.isOk()) { // TypeScript knows result.value exists here console.log(result.value);}
Transforms the successful value using the provided function. If this is an Ok, applies the function to the value and wraps the result in a new Ok.
The type of the transformed value
The function to transform the value
A new Result containing the transformed value
const result: Result<number> = ok(5);const doubled: Result<number> = result.map(x => x * 2);// doubled = Ok(10) Copy
const result: Result<number> = ok(5);const doubled: Result<number> = result.map(x => x * 2);// doubled = Ok(10)
A type-safe way to handle success and error cases. The Result type is used throughout the library to handle decoding results.