{"record":{"id":"47685aaa347140bb","repo":"can1357/oh-my-pi","slug":"intersection-of-a-expected-and-b-expected-is","errorCode":null,"errorMessage":"intersection of ${a.expected} and ${b.expected} is unsatisfiable","messagePattern":"intersection of (.+?) and (.+?) is unsatisfiable","errorType":"exception","errorClass":"OmpTypeError","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/type.ts","lineNumber":2126,"sourceCode":"\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}\n\tconst leftDomain = domainOf(a);\n\tconst rightDomain = domainOf(b);\n\tif (leftDomain !== undefined && rightDomain !== undefined && leftDomain !== rightDomain) {\n\t\tthrow new OmpTypeError(`intersection of ${leftDomain} and ${rightDomain} is unsatisfiable`);\n\t}\n\tif (a.k === \"anyobject\" && rightDomain === \"object\") return b;\n\tif (b.k === \"anyobject\" && leftDomain === \"object\") return a;\n\tconst members = [...(a.k === \"intersection\" ? a.members : [a]), ...(b.k === \"intersection\" ? b.members : [b])];\n\treturn { k: \"intersection\", members };\n}","sourceCodeStart":2108,"sourceCodeEnd":2144,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/type.ts#L2108-L2144","documentation":"When intersecting two instance types (constructed via instanceof-style checks), the library returns the narrower constructor if one is a subclass of the other. If the constructors are unrelated (neither prototype chain contains the other), no value can be an instance of both, so it throws with the human-readable expected names of both types.","triggerScenarios":"intersect(instance(Date), instance(Map)); or intersecting a class with an unrelated class after a refactor renamed/moved one; two versioned copies of the same class from different module instances (prototype chains differ).","commonSituations":"Refinements asserting instanceof checks on classes that were never in a subclass relationship; duplicate class copies from multiple bundler chunks or dual package installs; intersecting a base-class refinement with a sibling-class refinement.","solutions":["Use the common subclass if one actually extends the other","Replace the intersection with a union if either instance is acceptable","Model the constraint with a single class or an object/structural type instead of two instance checks","Deduplicate class copies so the same constructor identity is used"],"exampleFix":"// before\nintersect(instance(Error), instance(TypeError)); // TypeError extends Error: OK\nintersect(instance(Error), instance(Map)); // throws\n// after\nintersect(instance(TypeError), instance(Error)); // subtype first, or intersect related ctors only","handlingStrategy":"type-guard","validationCode":"function instancesCompatible(a, b) {\n  return a.ctor === b.ctor || a.ctor.prototype instanceof b.ctor || b.ctor.prototype instanceof a.ctor;\n}","typeGuard":"const isOmpTypeError = (e: unknown): e is OmpTypeError => e instanceof OmpTypeError;","tryCatchPattern":"try {\n  const t = intersect(instanceA, instanceB);\n} catch (err) {\n  if (err instanceof OmpTypeError && err.message.includes('is unsatisfiable')) {\n    // use a union or a structural (object) type instead\n  } else throw err;\n}","preventionTips":["Only intersect classes in a genuine subclass relationship","Avoid duplicate copies of the same class (dual installs/bundles) — they break prototype-chain checks","Prefer structural (object) types over instanceof when you only care about shape"],"tags":["types","instanceof","class","intersection","omptype"],"backgroundTag":"unsatisfiable-type-intersection","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}