Version: 0.1.1-draft
Status: Design Specification
Date: 2026-02-03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // example-usage.ts | |
| import { Result } from "better-result"; | |
| import { stubWithBetterResultHydration } from "./stub-with-better-result-hydration"; | |
| import type { MyDurableObject } from "./my-durable-object"; | |
| // In a Worker handler: | |
| export default { | |
| async fetch(req: Request, env: Env) { | |
| const id = env.MY_DO.idFromName("user-123"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { DurableObjectError } from "./errors"; | |
| import { Err, Ok, Result, type Result as ResultType } from "./result"; | |
| /** | |
| * Adds DurableObjectError to Result error unions, wraps non-Result returns. | |
| * - Promise<Result<T, E>> → Promise<Result<T, E | DurableObjectError>> | |
| * - Promise<T> → Promise<Result<T, DurableObjectError>> | |
| */ | |
| type AddDOError<R> = | |
| R extends Promise<ResultType<infer T, infer E>> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { describe, expect, it } from "vitest"; | |
| import { AsyncResult, Result } from "./result"; | |
| describe("Ok", () => { | |
| it("isOk returns true", () => { | |
| expect(Result.ok(1).isOk()).toBe(true); | |
| }); | |
| it("isErr returns false", () => { | |
| expect(Result.ok(1).isErr()).toBe(false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Mixin factory for discriminated error classes with typed props. | |
| * | |
| * Props become readonly fields; `message`/`cause` auto-wire to Error; `cause.stack` chains. | |
| * | |
| * @see [TypeScript Mixins](https://www.typescriptlang.org/docs/handbook/mixins.html) | |
| * @typeParam Tag - Literal string for `_tag` discriminant | |
| * @returns Base class to extend with optional generic props | |
| * | |
| * @example |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { describe, expect, it } from "vitest"; | |
| import { Result } from "./result"; | |
| describe("Ok", () => { | |
| it("isOk returns true", () => { | |
| expect(Result.ok(1).isOk()).toBe(true); | |
| }); | |
| it("isErr returns false", () => { | |
| expect(Result.ok(1).isErr()).toBe(false); |
A complete guide to durable workflow execution with Effect
A complete guide to reactive state management with Effect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Utility functions for creating `PromiseSettledResult` instances. | |
| * | |
| * Provides methods to construct fulfilled and rejected promise results, | |
| * ensuring they resolve asynchronously. | |
| */ | |
| const PromiseSettledResult = { | |
| /** | |
| * Creates a fulfilled `PromiseSettledResult`. | |
| * |
NewerOlder