{"record":{"id":"1fce5a0b2a73aced","repo":"can1357/oh-my-pi","slug":"cannot-apply-length-bound-to-ir-k","errorCode":null,"errorMessage":"cannot apply length bound to ${ir.k}","messagePattern":"cannot apply length bound to (.+?)","errorType":"exception","errorClass":"OmpTypeError","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/type.ts","lineNumber":2463,"sourceCode":"}\n\nfunction maxOf(a: number | undefined, b: number | undefined): number | undefined {\n\tif (a === undefined) return b;\n\tif (b === undefined) return a;\n\treturn Math.max(a, b);\n}\n\nfunction minOf(a: number | undefined, b: number | undefined): number | undefined {\n\tif (a === undefined) return b;\n\tif (b === undefined) return a;\n\treturn Math.min(a, b);\n}\n\nfunction withLengthBound(ir: IR, side: \"min\" | \"max\", bound: number): IR {\n\tif (ir.k === \"array\" || ir.k === \"string\") {\n\t\treturn side === \"min\" ? { ...ir, min: bound } : { ...ir, max: bound };\n\t}\n\tthrow new OmpTypeError(`cannot apply length bound to ${ir.k}`);\n}\n\nfunction withNumericBound(ir: IR, side: \"min\" | \"max\", bound: number, exclusive = false): IR {\n\tif (!Number.isFinite(bound)) throw new OmpTypeError(\"numeric bound must be finite\");\n\tif (ir.k === \"number\") {\n\t\treturn side === \"min\" ? { ...ir, min: bound, xmin: exclusive } : { ...ir, max: bound, xmax: exclusive };\n\t}\n\tif (ir.k === \"union\") {\n\t\treturn { ...ir, members: ir.members.map(member => withNumericBound(member, side, bound, exclusive)) };\n\t}\n\tthrow new OmpTypeError(`cannot apply numeric bound to ${ir.k}`);\n}\ninterface GenericParameter {\n\treadonly name: string;\n\treadonly constraintDef?: unknown;\n}\n\ninterface GenericMeta {","sourceCodeStart":2445,"sourceCodeEnd":2481,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/type.ts#L2445-L2481","documentation":"withLengthBound applies a min/max length constraint to an intermediate representation (IR) node, but only array and string IRs support length bounds. If called with any other kind (number, object, literal, …) it throws, indicating the constraint is being applied to a type that has no length concept.","triggerScenarios":"Internally, applying .min()/.max()-style length constraints during IR construction when the builder chain is attached to a non-length type; custom builder code that calls the internal bound helper on e.g. number().","commonSituations":"Chaining a length constraint onto a numeric or boolean builder by mistake (wrong builder selected); a refactor changed the base type but left the length constraint in place; misuse of internal IR helpers in extension code.","solutions":["Apply the length constraint to a string() or array() builder instead","Remove the length constraint from the non-length type","If a number bound was intended, use numeric bounds (min/max on number) rather than length bounds","Catch OmpTypeError to identify which IR kind received an invalid bound"],"exampleFix":"// before\nnumber().min(3); // length-style bound intended for strings/arrays\n// after\nstring().min(3); // or number().min(3) as a numeric bound","handlingStrategy":"validation","validationCode":"const supportsLengthBound = (t) => t?.k === 'string' || t?.k === 'array';\n// guard before applying: if (!supportsLengthBound(t)) skip or use numeric bounds","typeGuard":"const supportsLengthBound = (t) => t?.k === 'string' || t?.k === 'array';","tryCatchPattern":"try {\n  ir = withLengthBound(ir, 'min', n);\n} catch (err) {\n  if (err instanceof OmpTypeError && err.message.startsWith('cannot apply length bound')) {\n    // apply the appropriate bound kind for ir.k or drop the constraint\n  } else throw err;\n}","preventionTips":["Only chain .min()/.max() length constraints onto string() or array() builders","When a base type changes, audit attached constraints (length vs numeric)","Treat this error as a bug in builder wiring — fix the builder, not the message"],"tags":["types","bounds","internal","omptype"],"backgroundTag":"invalid-constraint-for-type","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}