Skip to main content
Result<T, E> represents either a success (Ok<T>) or a failure (Err<E>). Unlike try/catch, errors appear directly in the function signature, so TypeScript enforces that you handle them.

Creating results

Wrapping existing code

Use tryCatch to safely call any function that might throw:
Use fromPromise to wrap a Promise that might reject:

Chaining

All chaining methods skip the transformation when the result is an Err, so errors short-circuit automatically.

.map() and .mapErr()

Transform the value or the error without unwrapping:

.andThen()

Chain a function that itself returns a Result. Use this when the next step can also fail:

.orElse()

Recover from an error by returning a fallback Result:

Side effects

Use .tap() and .tapErr() to run side effects without modifying the result:

Consuming results

.match()

The cleanest way to handle both branches:

Type narrowing with .isOk() / .isErr()

.unwrap() and .unwrapOr()

.unwrap() throws if the result is an Err. Use it only when you are certain the result is Ok, or as a last resort:
.unwrap() throws the contained error if the result is Err. Prefer .match(), .unwrapOr(), or type narrowing for safe access.

Attaching debug context

Use .context() to annotate errors with information about where in the chain the failure occurred. Context accumulates in order from most recent to oldest:

The built-in .pipe() method

Result has a .pipe() method that lets you pass the result through a sequence of functions:
.pipe() on a Result is different from the standalone pipe function; it receives the full Result, not just the inner value.

ResultAsync is awaitable

ResultAsync<T, E> implements PromiseLike, so you can await it directly to get a synchronous Result<T, E>:

Combining multiple results

chas.shapeAsync()

Combine several ResultAsync values into a single shaped object. If any input is an Err, the first error is returned:

Parallel combinators

Do-notation with chas.go()

Use chas.go() to write sequential Result-based code without deeply nested .andThen chains. Yielding an Err short-circuits immediately: