oven-sh/bun · error · Error

This type already has a default value

Error message

This type already has a default value

What it means

Type-builder guard in the bindgen library: default() was called on a TypeImpl whose flags already contain a default. A schema type can only have one default; chaining default() twice is a code error in the .classes.ts schema.

Solutions

  1. Keep only one `.default(...)` per type
  2. If multiple variants are needed, model them as a union with a default on the union
  3. Re-run codegen after consolidating defaults
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/codegen/bindgen-lib-internal.ts:567 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/6772acaa33e81f37. Report an issue: GitHub.

Appendix: source

Thrown at src/codegen/bindgen-lib-internal.ts:567

    });
  }

  get required() {
    if (this.flags.required) {
      throw new Error("This type already has required set");
    }
    if (this.flags.required) {
      throw new Error("Cannot derive required on an optional type");
    }
    return new TypeImpl(this.kind, this.data, {
      ...this.flags,
      required: true,
    });
  }

  default(def: any) {
    if ("default" in this.flags) {
      throw new Error("This type already has a default value");
    }
    if (this.flags.required) {
      throw new Error("Cannot derive default on a required type");
    }
    this.assertDefaultIsValid(def);
    return new TypeImpl(this.kind, this.data, {
      ...this.flags,
      default: def,
    });
  }

  clamp(min?: number | bigint, max?: number | bigint) {
    return this.#rangeModifier(min, max, "clamp");
  }

  enforceRange(min?: number | bigint, max?: number | bigint) {
    return this.#rangeModifier(min, max, "enforce");
  }

View on GitHub (pinned to 8c5296ac45)