{"record":{"id":"903358bbae945352","repo":"can1357/oh-my-pi","slug":"cannot-apply-divisibility-to-this-ir-k","errorCode":null,"errorMessage":"cannot apply divisibility to ${this.ir.k}","messagePattern":"cannot apply divisibility to (.+?)","errorType":"exception","errorClass":"OmpTypeError","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/type.ts","lineNumber":835,"sourceCode":"\n\tatLeast(this: InternalType, bound: number): InternalType {\n\t\treturn makeType(withNumericBound(this.ir, \"min\", bound), this[kSteps], metaOf(this));\n\t},\n\n\tatMost(this: InternalType, bound: number): InternalType {\n\t\treturn makeType(withNumericBound(this.ir, \"max\", bound), this[kSteps], metaOf(this));\n\t},\n\n\tmoreThan(this: InternalType, bound: number): InternalType {\n\t\treturn makeType(withNumericBound(this.ir, \"min\", bound, true), this[kSteps], metaOf(this));\n\t},\n\n\tlessThan(this: InternalType, bound: number): InternalType {\n\t\treturn makeType(withNumericBound(this.ir, \"max\", bound, true), this[kSteps], metaOf(this));\n\t},\n\n\tdivisibleBy(this: InternalType, divisor: number): InternalType {\n\t\tif (this.ir.k !== \"number\") throw new OmpTypeError(`cannot apply divisibility to ${this.ir.k}`);\n\t\tif (!Number.isFinite(divisor) || divisor === 0) throw new OmpTypeError(\"divisor must be non-zero\");\n\t\treturn makeType({ ...this.ir, divisor }, this[kSteps], metaOf(this));\n\t},\n\n\tpositive(this: InternalType): InternalType {\n\t\treturn makeType(withNumericBound(this.ir, \"min\", 0, true), this[kSteps], metaOf(this));\n\t},\n\n\tnegative(this: InternalType): InternalType {\n\t\treturn makeType(withNumericBound(this.ir, \"max\", 0, true), this[kSteps], metaOf(this));\n\t},\n\n\tnonNegative(this: InternalType): InternalType {\n\t\treturn makeType(withNumericBound(this.ir, \"min\", 0), this[kSteps], metaOf(this));\n\t},\n\n\tnonPositive(this: InternalType): InternalType {\n\t\treturn makeType(withNumericBound(this.ir, \"max\", 0), this[kSteps], metaOf(this));","sourceCodeStart":817,"sourceCodeEnd":853,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/type.ts#L817-L853","documentation":"`.divisibleBy(n)` is only defined for number types. `divisibleBy` checks `this.ir.k !== \"number\"` and throws an OmpTypeError naming the actual kind when called on any other type (string, object, boolean, etc.). Divisibility is a numeric-only constraint, so applying it elsewhere is a type-level misuse.","triggerScenarios":"Calling `.divisibleBy(2)` on a non-number type, e.g. `type('string').divisibleBy(2)`, `type('boolean').divisibleBy(1)`, or chaining it onto an object/union type.","commonSituations":"Chaining constraint builders fluently and landing on the wrong base type; intending `type('number').divisibleBy(...)` but the expression resolves to a union or string due to a wrong type expression.","solutions":["Ensure the receiver is a number type: `type('number').divisibleBy(2)`.","If constraining integers, use `type('number.integer').divisibleBy(2)`.","Check the message's `k` value to see which kind the receiver actually was and fix the base type expression."],"exampleFix":"// before\nconst T = type('string').divisibleBy(2); // throws: cannot apply divisibility to string\n\n// after\nconst T = type('number').divisibleBy(2);","handlingStrategy":"type-guard","validationCode":"// ensure the receiver is numeric before chaining\nconst base = type('number'); // not string/object/union\nconst T = base.divisibleBy(2);","typeGuard":"function isNumberType(t) {\n  try { return t.expression.startsWith('number'); } catch { return false; }\n}","tryCatchPattern":"try {\n  const T = maybeType.divisibleBy(2);\n} catch (e) {\n  if (e instanceof OmpTypeError && e.message.startsWith('cannot apply divisibility')) {\n    // use a numeric base type instead\n  } else throw e;\n}","preventionTips":["Only chain numeric constraints (divisibleBy, min, max, positive) off explicit `type('number')` bases.","Avoid fluent chains on unions — constraints apply to the whole union kind.","Name numeric-constraint builders in one module so misuse is reviewable."],"tags":["type-error","numeric-constraint","api-misuse"],"backgroundTag":"constraint-applied-to-wrong-type","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}