Result type for representing success (Ok) or failure (Err) values.
Result is a type-safe way to handle operations that can fail, similar to Rust's
Result type. It forces explicit handling of both success and error cases without
throwing exceptions.
Example
functiondivide(a: number, b: number): Result<number> { if (b === 0) { returnResult.Err('Division by zero'); } returnResult.Ok(a / b); }
Result type for representing success (Ok) or failure (Err) values.
Result is a type-safe way to handle operations that can fail, similar to Rust's Result type. It forces explicit handling of both success and error cases without throwing exceptions.
Example