Represents a failed operation with an error message.
The type that would have been returned if successful
Creates a new Err instance containing an error message.
The error message describing what went wrong
Readonly
Type guard to check if this Result is an Ok. Always returns false for Err instances.
false for Err instances
const result: Result<number> = err("Invalid input");if (!result.isOk()) { // TypeScript knows result.error exists here console.log(result.error);} Copy
const result: Result<number> = err("Invalid input");if (!result.isOk()) { // TypeScript knows result.error exists here console.log(result.error);}
Returns a new Err with the same error message but a different type parameter. Since this represents an error, the transform function is never called.
The new type parameter
The function that would have transformed the value (ignored)
A new Err with the same error message
const result: Result<number> = err("Invalid input");const mapped: Result<string> = result.map(x => x.toString());// mapped = Err("Invalid input") Copy
const result: Result<number> = err("Invalid input");const mapped: Result<string> = result.map(x => x.toString());// mapped = Err("Invalid input")
Represents a failed operation with an error message.