A Rust-inspired Result and Option library for writing more correct
TypeScript, with an ESLint plugin that helps catch ignored results.
Both types have first-class async support. Use AsyncResult and AsyncOption
to chain operations without awaiting every step, and methods such as asyncMap,
asyncAndThen, and asyncMatch for asynchronous callbacks.
Also check out eslint-plugin-resulto. It warns when a
Resultis ignored, helping you handle errors consistently.
npm install resultoWith Deno:
deno add jsr:@resulto/corehttps://jsr.io/@resulto/core/doc
Exceptions are awkward to work with in JavaScript. Any function can throw, its
signature does not tell you which errors to expect, and the language cannot
require callers to catch them. It is therefore easy to forget an error path
until it fails at runtime. Representing errors as Result values makes failure
part of the type and, together with the ESLint plugin, requires callers to use
the result. Option does the same for values that may be absent. This makes
both cases part of normal, explicit control flow.
There are several Result implementations for TypeScript, but I couldn't find a
full-fledged library that combined the three things I wanted:
- A familiar, complete API. Resulto closely mirrors Rust's
ResultandOptionAPIs, bringing their well-established patterns to TypeScript instead of offering only a small set of helpers. - Async support throughout. Real applications perform network requests,
database queries, and other asynchronous work.
AsyncResultandAsyncOptionlet you compose those operations without repeatedly unwrapping values or breaking a chain with intermediateawaitexpressions. - Enforcement at development time. Returning a
Resultonly helps when the caller uses it. The ESLint plugin warns about ignored synchronous and asynchronous results, catching mistakes before they become lost errors.
This library brings these pieces together so explicit error handling remains practical across an entire TypeScript codebase, not just in isolated functions.