can1357/oh-my-pi · error · OmpTypeError

array length intersection is unsatisfiable

Error message

array length intersection is unsatisfiable

What it means

Intersecting two array types intersects their element types and length bounds (min = max of mins, max = min of maxs). If the resulting length range is empty (min > max), the library throws because no array can satisfy both operands.

Source

Thrown at packages/omptype/src/type.ts:2116

		}
		if (a.divisor !== undefined && b.divisor !== undefined && a.divisor !== b.divisor) {
			return { k: "intersection", members: [a, b] };
		}
		return {
			k: "number",
			int: a.int || b.int,
			divisor: a.divisor ?? b.divisor,
			min,
			max,
			xmin,
			xmax,
		};
	}
	if (a.k === "array" && b.k === "array") {
		const min = maxOf(a.min, b.min);
		const max = minOf(a.max, b.max);
		if (min !== undefined && max !== undefined && min > max) {
			throw new OmpTypeError("array length intersection is unsatisfiable");
		}
		return { k: "array", el: intersect(a.el, b.el), min, max };
	}
	if (a.k === "tuple" && b.k === "tuple") return intersectTuples(a, b);
	if (a.k === "tuple" && b.k === "array") return intersectTupleWithArray(a, b);
	if (a.k === "array" && b.k === "tuple") return intersectTupleWithArray(b, a);
	if (a.k === "instance" && b.k === "instance") {
		if (a.ctor === b.ctor || a.ctor.prototype instanceof b.ctor) return a;
		if (b.ctor.prototype instanceof a.ctor) return b;
		throw new OmpTypeError(`intersection of ${a.expected} and ${b.expected} is unsatisfiable`);
	}
	if (a.k === b.k && ["null", "undefined", "boolean", "bigint", "symbol", "anyobject"].includes(a.k)) return a;
	if (
		(a.k === "object" && (b.k === "array" || b.k === "tuple")) ||
		(b.k === "object" && (a.k === "array" || a.k === "tuple"))
	) {
		return { k: "intersection", members: [a, b] };
	}

View on GitHub (pinned to 9690622007)

Solutions

  1. Adjust the min/max bounds so they overlap
  2. Remove the length constraint from one operand
  3. Align the element types too — the element intersect happens after this check and can fail separately
  4. Catch OmpTypeError around intersect to surface the conflicting bounds

Example fix

// before
intersect(array(string).min(4), array(string).max(2));
// after
intersect(array(string).min(1), array(string).max(4));
Defensive patterns

Strategy: validation

Validate before calling

function arrayBoundsOk(specs) {
  const min = Math.max(...specs.map(s => s.min ?? 0));
  const max = Math.min(...specs.map(s => s.max ?? Infinity));
  return min <= max;
}

Type guard

const isOmpTypeError = (e: unknown): e is OmpTypeError => e instanceof OmpTypeError;

Try / catch

try {
  const t = intersect(a, b);
} catch (err) {
  if (err instanceof OmpTypeError && err.message === 'array length intersection is unsatisfiable') {
    throw new Error(`Array length bounds conflict: ${describe(a)} vs ${describe(b)}`);
  }
  throw err;
}

Prevention

When it happens

Trigger: intersect(array(string).min(4), array(string).max(2)); or intersecting a fixed-ish array constraint with a capped one whose bounds no longer overlap.

Common situations: A schema requiring at least N items intersected with a limit of fewer than N; tuple-derived array bounds colliding with an explicit max after a refactor; list-length validation split across two layers.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/033550e427071cab. Report an issue: GitHub.