{"record":{"id":"033550e427071cab","repo":"can1357/oh-my-pi","slug":"array-length-intersection-is-unsatisfiable","errorCode":null,"errorMessage":"array length intersection is unsatisfiable","messagePattern":"array length intersection is unsatisfiable","errorType":"exception","errorClass":"OmpTypeError","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/type.ts","lineNumber":2116,"sourceCode":"\t\t}\n\t\tif (a.divisor !== undefined && b.divisor !== undefined && a.divisor !== b.divisor) {\n\t\t\treturn { k: \"intersection\", members: [a, b] };\n\t\t}\n\t\treturn {\n\t\t\tk: \"number\",\n\t\t\tint: a.int || b.int,\n\t\t\tdivisor: a.divisor ?? b.divisor,\n\t\t\tmin,\n\t\t\tmax,\n\t\t\txmin,\n\t\t\txmax,\n\t\t};\n\t}\n\tif (a.k === \"array\" && b.k === \"array\") {\n\t\tconst min = maxOf(a.min, b.min);\n\t\tconst max = minOf(a.max, b.max);\n\t\tif (min !== undefined && max !== undefined && min > max) {\n\t\t\tthrow new OmpTypeError(\"array length intersection is unsatisfiable\");\n\t\t}\n\t\treturn { k: \"array\", el: intersect(a.el, b.el), min, max };\n\t}\n\tif (a.k === \"tuple\" && b.k === \"tuple\") return intersectTuples(a, b);\n\tif (a.k === \"tuple\" && b.k === \"array\") return intersectTupleWithArray(a, b);\n\tif (a.k === \"array\" && b.k === \"tuple\") return intersectTupleWithArray(b, a);\n\tif (a.k === \"instance\" && b.k === \"instance\") {\n\t\tif (a.ctor === b.ctor || a.ctor.prototype instanceof b.ctor) return a;\n\t\tif (b.ctor.prototype instanceof a.ctor) return b;\n\t\tthrow new OmpTypeError(`intersection of ${a.expected} and ${b.expected} is unsatisfiable`);\n\t}\n\tif (a.k === b.k && [\"null\", \"undefined\", \"boolean\", \"bigint\", \"symbol\", \"anyobject\"].includes(a.k)) return a;\n\tif (\n\t\t(a.k === \"object\" && (b.k === \"array\" || b.k === \"tuple\")) ||\n\t\t(b.k === \"object\" && (a.k === \"array\" || a.k === \"tuple\"))\n\t) {\n\t\treturn { k: \"intersection\", members: [a, b] };\n\t}","sourceCodeStart":2098,"sourceCodeEnd":2134,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/type.ts#L2098-L2134","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Adjust the min/max bounds so they overlap","Remove the length constraint from one operand","Align the element types too — the element intersect happens after this check and can fail separately","Catch OmpTypeError around intersect to surface the conflicting bounds"],"exampleFix":"// before\nintersect(array(string).min(4), array(string).max(2));\n// after\nintersect(array(string).min(1), array(string).max(4));","handlingStrategy":"validation","validationCode":"function arrayBoundsOk(specs) {\n  const min = Math.max(...specs.map(s => s.min ?? 0));\n  const max = Math.min(...specs.map(s => s.max ?? Infinity));\n  return min <= max;\n}","typeGuard":"const isOmpTypeError = (e: unknown): e is OmpTypeError => e instanceof OmpTypeError;","tryCatchPattern":"try {\n  const t = intersect(a, b);\n} catch (err) {\n  if (err instanceof OmpTypeError && err.message === 'array length intersection is unsatisfiable') {\n    throw new Error(`Array length bounds conflict: ${describe(a)} vs ${describe(b)}`);\n  }\n  throw err;\n}","preventionTips":["Check min <= max on every array builder","Keep list-length policy (required count vs cap) in one place","Remember element types also intersect — align them to avoid a follow-on failure"],"tags":["types","array","bounds","validation","omptype"],"backgroundTag":"unsatisfiable-type-intersection","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}