{"record":{"id":"945dd130318bb875","repo":"can1357/oh-my-pi","slug":"intersection-with-never-is-unsatisfiable","errorCode":null,"errorMessage":"intersection with never is unsatisfiable","messagePattern":"intersection with never is unsatisfiable","errorType":"exception","errorClass":"OmpTypeError","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/type.ts","lineNumber":2003,"sourceCode":"\t\ttarget[kIntersections] ??= new WeakMap<IR, IR>();\n\t\tconst cache = target[kIntersections];\n\t\tconst existing = cache.get(b);\n\t\tif (existing !== undefined) return existing;\n\t\tlet resolved: IR | undefined;\n\t\tconst reference: IR = {\n\t\t\tk: \"alias\",\n\t\t\tname: a.k === \"alias\" ? a.name : b.k === \"alias\" ? b.name : \"intersection\",\n\t\t\tresolve: () =>\n\t\t\t\t(resolved ??= intersectResolved(a.k === \"alias\" ? a.resolve() : a, b.k === \"alias\" ? b.resolve() : b)),\n\t\t};\n\t\tcache.set(b, reference);\n\t\treturn reference;\n\t}\n\treturn intersectResolved(a, b);\n}\n\nfunction intersectResolved(a: IR, b: IR): IR {\n\tif (a.k === \"never\" || b.k === \"never\") throw new OmpTypeError(\"intersection with never is unsatisfiable\");\n\tif (a.k === \"unknown\") return b;\n\tif (b.k === \"unknown\") return a;\n\tif (a === b) return a;\n\tif (a.k === \"morph\" && b.k === \"morph\") {\n\t\tif (a.fn !== b.fn || a.out !== b.out) {\n\t\t\tthrow new OmpTypeError(\"intersection of distinct morphs is indeterminate\");\n\t\t}\n\t\treturn { ...a, input: intersect(a.input, b.input) };\n\t}\n\tif (a.k === \"morph\") return { ...a, input: intersect(a.input, b) };\n\tif (b.k === \"morph\") return { ...b, input: intersect(a, b.input) };\n\tif (a.k === \"sub\" && a.schema.hasSteps) {\n\t\tif (b.k === \"sub\" && b.schema.hasSteps) {\n\t\t\tif (a.schema === b.schema) return a;\n\t\t\tthrow new OmpTypeError(\"intersection of distinct morphs is indeterminate\");\n\t\t}\n\t\tconst schema = a.schema as InternalType;\n\t\treturn embed(makeType(intersect(schema.ir, b), schema[kSteps], metaOf(schema)));","sourceCodeStart":1985,"sourceCodeEnd":2021,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/type.ts#L1985-L2021","documentation":"intersectResolved() treats a never operand as fatal: never is the empty type, and omptype's intersection compiler does not model the (mathematically valid but useless) never result, so it throws to surface the mistake at schema-build time. If you legitimately want never, construct it explicitly rather than intersecting into it.","triggerScenarios":"intersect(never(), string), or an intersection where one argument's IR resolved to never (e.g. an alias to never or an empty construct).","commonSituations":"Guarding 'impossible' branches by intersecting with never; a generic helper that receives never from an empty union; refactoring that accidentally aliases a schema to never().","solutions":["Remove the never operand — the intersection is vacuous; just use the other type or never() directly","If one side comes from a generic/union, short-circuit: if (schema.isNever) return never()","Check where the never-typed value leaked from (usually an empty array inferred as never[] or an empty union)"],"exampleFix":"// before\nconst T = intersect(configured, never())\n// after\nconst T = configured // or never() if emptiness is intended","handlingStrategy":"validation","validationCode":"function safeIntersect(a, b) {\n  if (a.isNever || b.isNever) return never();\n  return intersect(a, b);\n}","typeGuard":"function isNeverSchema(t): boolean {\n  return t != null && t.ir?.k === 'never';\n}","tryCatchPattern":"try {\n  return intersect(a, b);\n} catch (err) {\n  if (err instanceof OmpTypeError && err.message.includes('never')) {\n    return never(); // intersection with never is vacuously never\n  }\n  throw err;\n}","preventionTips":["Short-circuit never operands before calling intersect","Watch for empty unions/arrays inferring never in generic helpers","Never use intersect with never() as an 'impossible branch' guard"],"tags":["omptype","never","intersection","unsatisfiable"],"backgroundTag":"unsatisfiable-type-intersection","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}