npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@sandlada/result

v0.20260811.0

Published

Type-safe Result Pattern & ROP for TypeScript — Explicit Error Handling without Exceptions

Readme

@sandlada/result

Codecov NPM Downloads NPM Version GitHub License

Open in StackBlitz

@sandlada/result is a TypeScript library implementing the Result pattern — a type-safe, exception-free approach to error handling. It makes error flows explicit in the type system so you never wonder whether a function can fail.

Unlike traditional Result libraries that hardcode a single error type, @sandlada/result is fully generic: you bring your own error shapes (discriminated unions, classes, or plain objects).

:zap: Highlights

  • Fully generic TError — define your own error types
  • Pure FP — data-last curried operators (pipe, map, bind) with discriminated union types
  • Option type — IOption<T> (Some / None) with curried operators
  • Async-native — asyncOk/asyncErr factories + pipeAsync for Promise-based railways, plus lazy AsyncResult / AsyncOption thunks
  • Railway Oriented Programming built-in — map, bind, orElse, match, tap, combine
  • Reliability — bounded retry, timeout, race, any, allSettled for production pipelines
  • Observability — breadcrumb withPath / ctx / tapErrContext + format / inspect / installObserver
  • JSON serializable — result and option objects survive JSON.stringify
  • Zero dependencies
  • ESM-only, strict TypeScript
  • Inspired by the C# Result pattern and Rust's Option<T>

:eyes: Installation

npm i @sandlada/result

ESM only. This package cannot be used with require(). Your project must use ESM (import) or dynamic import().

:ship: Quick Start

The main barrel @sandlada/result is type-focused. Its only runtime value is moduleMarker, used to materialize the entry and sourcemap; functional runtime values come from dedicated subpath packages — pick the one that matches your shape.

import type { IResultOfT } from '@sandlada/result';              // type contracts
import { ok, err } from '@sandlada/result/factories';             // core constructors
import { map, unwrapOr } from '@sandlada/result/operators';       // sync operators
import { pipe } from '@sandlada/result/composition';              // pipe / composeK / safeTry

// Define your error type (discriminated union recommended)
type AppError =
  | { kind: 'NotFound'; id: string }
  | { kind: 'Validation'; fields: Record<string, string> };

function getUser(id: string): IResultOfT<User, AppError> {
  if (!id) {
    return err<AppError>({ kind: 'Validation', fields: { id: 'Required' } }) as IResultOfT<User, AppError>;
  }
  const user = db.find(id);
  if (!user) {
    return err<AppError>({ kind: 'NotFound', id }) as IResultOfT<User, AppError>;
  }
  return ok(user);
}

// FP curried style
const name = pipe(
  getUser('42'),
  map(u => u.name),
  unwrapOr('Unknown'),
);

Why subpath imports? @sandlada/result exposes many types — IResultOfT, IOption, AsyncResult, AsyncOption. Names like map, bind, match exist for both IResultOfT and IOption. The compiler can't disambiguate; the package layout does. Subpath imports make the type explicit at the call site and keep tree-shaking total. See ARCH.md ADR 10.

:ledger: API Overview

All exports are listed in SPEC.md with links to their source files. Full type signatures and JSDoc live in the source.

| Export path | Contents | | --- | --- | | @sandlada/result | Type-focused barrel — IResult, IResultOfT, IOption, AsyncResult, AsyncOption, plus the runtime moduleMarker. Functional runtime values must use a subpath. | | @sandlada/result/factories | Core constructors (ok, err, asyncOk, asyncErr, tryCatch, fromPromise, …). | | @sandlada/result/operators | Sync operators on IResultOfT (map, bind, match, pipe, …). | | @sandlada/result/option | Sync IOption<T> operators (ofSome, ofNone, map, bind, okOr, transpose, …). | | @sandlada/result/async-result | Lazy AsyncResult<T, E> thunk operators. | | @sandlada/result/async-option | Lazy AsyncOption<T> thunk operators. | | @sandlada/result/promise-result | Eager async operators on Promise<IResultOfT>. | | @sandlada/result/promise-option | Eager async operators on Promise<IOption>. | | @sandlada/result/composition | pipe, composeK, safeTry, pipeAsync, composeKAsync. | | @sandlada/result/adapters | toOption, fromOption, switchFn, liftMap, tee, … | | @sandlada/result/combine | combine, combineWithAllErrors, all. | | @sandlada/result/reliability | retry, retryLazy, timeout, race, any, allSettled. | | @sandlada/result/observability | ctx, withPath, format, inspect, installObserver, … | | @sandlada/result/primitives | cond, condErr, sequence, reduce, partitionOption, lift. | | @sandlada/result/types | Same type contracts as the main barrel, plus its own runtime moduleMarker. Kept for backward compatibility. |

:package: Integration Pattern

Bind your error type once and eliminate generic boilerplate:

// app-result.ts
import { ok, err } from '@sandlada/result/factories';
import type { IResultOfT } from '@sandlada/result';
import type { AppError } from './errors.js';

export type AppResult<T = void> = IResultOfT<T, AppError>;

export const AppResult = {
  Success<T>(value?: T): AppResult<T> { return (value === undefined ? ok() : ok(value)) as unknown as AppResult<T>; },
  Failure(error: AppError): AppResult<never> { return err(error) as unknown as AppResult<never>; },
} as const;
// usage — no TError generic anywhere
function getUser(id: string): AppResult<User> {
  if (!id) return AppResult.Failure({ kind: 'Validation', fields: { id: 'Required' } });
  return AppResult.Success({ id, name: 'Alice' });
}

:ledger: Further Reading

  • SPEC.md — API index with links to each source file
  • ARCH.md — internal architecture and contributor documentation
  • AGENTS.md — AI agent conventions and project metadata for tool-assisted development

License

MIT