Canonical Result type definition

Rule

A library that returns Result defines it in src/result.ts with exactly the text below and nothing else, and re-exports it from src/index.ts as a type. Do not import Result from another package, rename its fields, or add helper functions to result.ts.

Do

export type Result<T, E = Error> =
  | { readonly ok: true; readonly value: T }
  | { readonly ok: false; readonly error: E };
// src/index.ts
export type { Result } from './result.js';

Don’t

// E = 'Error' makes the default error type the string literal 'Error'.
export type Result<T, E = 'Error'> =
  | { ok: true; value: T }
  | { ok: false; error: E };

Rationale

A7 libraries have no runtime dependencies, so each one carries its own copy. Identical copies are interchangeable because TypeScript types are structural, so a consumer can handle results from several libraries with one type. The copy check in ops-core is planned; until it runs, review stage S2 compares the file.