{"record":{"id":"2297b6d12f965a11","repo":"can1357/oh-my-pi","slug":"literal-is-excluded-by-the-intersection","errorCode":null,"errorMessage":"literal is excluded by the intersection","messagePattern":"literal is excluded by the intersection","errorType":"exception","errorClass":"OmpTypeError","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/type.ts","lineNumber":2041,"sourceCode":"\tif (b.k === \"sub\" && b.schema.hasSteps) return intersect(b, a);\n\tif (a.k === \"union\" || b.k === \"union\") {\n\t\tconst union = a.k === \"union\" ? a : b.k === \"union\" ? b : undefined;\n\t\tif (union === undefined) throw new OmpTypeError(\"union intersection invariant failed\");\n\t\tconst branches = union.members;\n\t\tconst other = a.k === \"union\" ? b : a;\n\t\tconst members: IR[] = [];\n\t\tfor (const branch of branches) {\n\t\t\ttry {\n\t\t\t\tmembers.push(intersect(branch, other));\n\t\t\t} catch (error) {\n\t\t\t\tif (!(error instanceof OmpTypeError)) throw error;\n\t\t\t}\n\t\t}\n\t\tif (members.length === 0) throw new OmpTypeError(\"intersection has no satisfiable branches\");\n\t\treturn members.length === 1 ? members[0] : { k: \"union\", members };\n\t}\n\tif (a.k === \"lit\") {\n\t\tif (walk(b, a.v) instanceof OmpErrors) throw new OmpTypeError(\"literal is excluded by the intersection\");\n\t\treturn a;\n\t}\n\tif (b.k === \"lit\") return intersect(b, a);\n\tif (a.k === \"object\" && b.k === \"object\") {\n\t\tconst props = [...a.props];\n\t\tfor (const bp of b.props) {\n\t\t\tconst index = props.findIndex(prop => prop.key === bp.key);\n\t\t\tif (index < 0) props.push(bp);\n\t\t\telse {\n\t\t\t\tconst ap = props[index];\n\t\t\t\tconst required = (!ap.opt && !ap.hasDefault) || (!bp.opt && !bp.hasDefault);\n\t\t\t\tif (ap.hasDefault && bp.hasDefault && !Object.is(ap.def, bp.def)) {\n\t\t\t\t\tthrow new OmpTypeError(\n\t\t\t\t\t\t`ParseError: Invalid intersection of default values ${String(ap.def)} & ${String(bp.def)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst defaulted = required ? undefined : ap.hasDefault ? ap : bp.hasDefault ? bp : undefined;\n\t\t\t\tprops[index] = {","sourceCodeStart":2023,"sourceCodeEnd":2059,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/type.ts#L2023-L2059","documentation":"Thrown when intersecting a literal type with another type: `walk(b, a.v)` returns an OmpErrors validation failure, meaning the other type cannot ever accept the literal's value. The library refuses to construct the intersection because the literal is provably not a member of the other type.","triggerScenarios":"intersect(lit('a'), someType) where someType rejects 'a' — e.g. a literal intersected with a number type, a string constraint that excludes the literal (length/URL bounds), or a different literal.","commonSituations":"Refining a config key to a specific allowed value that conflicts with an enum/constraint added elsewhere; narrowing a version literal against a range that no longer includes it after an upgrade.","solutions":["Verify the literal value satisfies the other type's constraints (domain, length, pattern)","Update the literal or the other type so the value is accepted","Replace the intersection with the literal alone if the other constraint is redundant","Catch OmpTypeError at intersect time to report the conflicting literal"],"exampleFix":"// before\nintersect(lit('https'), string().max(3));\n// after\nintersect(lit('https'), string().max(5));","handlingStrategy":"validation","validationCode":"function literalFits(value, t) {\n  const errs = walk(t, value); // or t.validate(value) equivalent\n  return !(errs instanceof OmpErrors);\n}\n// guard: literalFits('a', otherType) before intersect(lit('a'), otherType)","typeGuard":"const isOmpTypeError = (e: unknown): e is OmpTypeError => e instanceof OmpTypeError;","tryCatchPattern":"try {\n  const t = intersect(lit('a'), other);\n} catch (err) {\n  if (err instanceof OmpTypeError && err.message.includes('literal is excluded')) {\n    // fall back to `other` alone or report the conflicting literal\n  } else throw err;\n}","preventionTips":["Validate the literal against the other type before intersecting","Keep allowed-value lists and their constraints in one place so they cannot drift","Avoid intersecting literals with range-constrained types unless you recheck bounds on edits"],"tags":["types","literal","intersection","omptype"],"backgroundTag":"unsatisfiable-type-intersection","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}