The result of an operation that can fail: either Ok or Err. Narrow with the success discriminant or the isOk/isErr guards.
Ok
Err
success
isOk
isErr
The success value type
The error type (defaults to Error)
Error
function parsePort(raw: string): Result<number, RangeError> { const port = Number(raw); return Number.isInteger(port) && port > 0 && port < 65536 ? ok(port) : err(new RangeError(`Invalid port: ${raw}`));}const result = parsePort('3000');if (result.success) { listen(result.value);} Copy
function parsePort(raw: string): Result<number, RangeError> { const port = Number(raw); return Number.isInteger(port) && port > 0 && port < 65536 ? ok(port) : err(new RangeError(`Invalid port: ${raw}`));}const result = parsePort('3000');if (result.success) { listen(result.value);}
0.1.0
The result of an operation that can fail: either
OkorErr. Narrow with thesuccessdiscriminant or theisOk/isErrguards.