oven-sh/bun · error · Error

Cannot derive default on a required type

Error message

Cannot derive default on a required type

What it means

Error "Cannot derive default on a required type" thrown in oven-sh/bun.

Source

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

  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");
  }

  get nonNull() {
    if (this.flags.nonNull) {

View on GitHub (pinned to 8c5296ac45)

When it happens

Trigger: Thrown at src/codegen/bindgen-lib-internal.ts:570 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/58eecc5385969775. Report an issue: GitHub.