Skip to main content
Get started with better-result in seconds using your preferred package manager.

Package Manager Installation

npm install better-result
For new projects, use the interactive CLI to get everything set up:
npx better-result init
This interactive setup will:
  1. Install the better-result package
  2. Optionally fetch source code via opensrc for better AI context
  3. Install the adoption skill + /adopt-better-result command for AI agents
  4. Optionally launch your agent to start refactoring
The adoption skill helps AI coding agents (OpenCode, Claude, Codex) guide you through converting existing error handling to better-result patterns.

Requirements

TypeScript 5.0+ is required. better-result uses modern TypeScript features for type safety.

TypeScript Configuration

For the best experience, enable strict mode in your tsconfig.json:
tsconfig.json
{
  "compilerOptions": {
    "strict": true,
    "moduleResolution": "bundler", // or "node16", "nodenext"
    "esModuleInterop": true,
    "skipLibCheck": false
  }
}

Runtime Support

better-result is ESM-only and works with:
  • Node.js 16.0+
  • Bun (all versions)
  • Deno (with npm specifier: npm:better-result)
  • Browsers (via bundlers like Vite, webpack, or esbuild)
CommonJS is not supported. If you need CommonJS, you’ll need to transpile the package yourself.

Verify Installation

Create a simple test file to verify everything works:
test.ts
import { Result } from "better-result";

const result = Result.ok(42);
console.log(result.value); // 42

const error = Result.err("something went wrong");
console.log(error.error); // "something went wrong"

console.log("✅ better-result is installed correctly!");
Run it:
node test.ts
You should see:
42
something went wrong
✅ better-result is installed correctly!

Migrating from v1?

If you’re upgrading from better-result v1.x to v2.x, use the migration CLI:
npx better-result migrate
This will guide you through the breaking changes and help automate the migration process.
See the Migration Guide for detailed information about what changed in v2.

Next Steps

Now that better-result is installed, let’s build something:

Quickstart Tutorial

Build your first Result-based application with a step-by-step guide