API Reference

@sapphire/result

Rust-style Result type for TypeScript, representing success or error without throwing, with pattern matching.

Official Documentation ↗
CompatibilityThis documentation covers version v2.2. Check the official docs for the latest API surface.

Installation

npmnpm install @sapphire/result

Methods

@sapphire/result is rust-style result type for typescript, representing success or error without throwing, with pattern matching. This page documents the core methods, installation, and common usage patterns for the current stable release.

Installation

Install @sapphire/result with your preferred package manager using the command shown in the frontmatter. The package is published to the npm registry and ships with TypeScript types where applicable.

Core methods

The methods listed in the frontmatter cover the primary API surface. Each signature reflects the v2.2 release. Consult the official documentation linked in sourceUrl for advanced options, edge cases, and breaking changes between major versions.

Frequently asked questions

The faq section in the frontmatter answers the most common questions about @sapphire/result, including comparisons with alternatives, configuration tips, and runtime requirements. If your question is not covered, check the source URL for the full guide.

FAQ

Why use Result over try/catch?
Result makes error handling explicit in the type system; callers cannot forget to handle the error case.
Does it support async?
Yes. Use Result.fromAsync(fn) to wrap a promise-returning function.
Is it zero-dependency?
Yes. It is a single-file utility with no dependencies.