migrate-better-result-3

Migrates TypeScript codebases from better-result 2.x to 3.0 using codemods and API references.

1.9k|43|Updated Jan 9, 2026
One-click install
npx skills add https://github.com/dmmulroy/better-result --skill migrate-better-result-3
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: migrate-better-result-3
Source: https://github.com/dmmulroy/better-result/tree/main/skills/migrate-better-result-3
Command: npx skills add https://github.com/dmmulroy/better-result --skill migrate-better-result-3

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires typescript, and includes scripts (resource) and references (resource) components.

What problem does it solve?

Upgrading the better-result library from 2.x to 3.0 breaks TaggedError class syntax, removes Result serialization helpers, and changes type inference for recovery and matching APIs, leaving teams with dozens of compiler errors to resolve manually.

Core Features & Use Cases

  • Automated TaggedError codemod: A TypeScript AST-based script lists, rewrites, and verifies v2 trailing factory calls into the v3 class heritage shape while preserving constructors and formatting.
  • Serialization codec migration: Reference guides walk through replacing removed Result.serialize/deserialize/hydrate calls with per-boundary Result.codec contracts, including safe versus unsafe error policies.
  • Inference and API reconciliation: An audited 2.10.0 to 3.0 API diff covers tryRecover widening, matchError unions, partition typing, iterable tagged errors, and new retry controls.
  • Use Case: A team upgrades their package.json to better-result 3.0, runs the codemod to fix TaggedError declarations, rebuilds serialization boundaries as codecs, and resolves remaining compiler diagnostics until the full test suite passes.

Quick Start

Migrate my TypeScript project from better-result 2.x to 3.0, fixing TaggedError syntax, serialization helpers, and any type errors.

Frequently Asked Questions about migrate-better-result-3

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate better-result from 2.x to 3.0?

Inventory all TaggedError, Result.serialize, matchError, and tryRecover usages, then run the codemod script to rewrite v2 TaggedError trailing calls. Replace serialization helpers with Result.codec contracts and resolve remaining compiler diagnostics using the API diff reference.

How do I update TaggedError classes for better-result 3.0?

Remove the empty trailing call after the props type argument so the class extends TaggedError("Tag")<Props> directly. The included migrate-tagged-error-v3.mjs script automates this with --list, --write, and --check modes.

What replaces Result.serialize and Result.deserialize in better-result 3.0?

Result.codec replaces them with Standard Schema validation for Ok and Err payloads in both directions. Each boundary contract gets four schemas, and serializeUnsafe or deserializeUnsafe can be used when contract mismatch is treated as a defect.

Does better-result 3.0 change tryRecover type inference?

Yes, tryRecover and tryRecoverAsync now preserve the original success type and union it with a different recovered success type. Downstream code must handle the honest A | B union instead of coercing recovery back to the original type.

Why do Vitest assertions fail on tagged errors after upgrading to better-result 3.0?

Tagged errors are iterable in v3, so structural deep-equality matchers can advance the error's generator and trigger unreachable errors. Assert the Result status first, then compare tagged errors by identity or selected fields.