{"record":{"id":"189c27a238d01841","repo":"can1357/oh-my-pi","slug":"cannot-apply-int-to-schema-ir-k","errorCode":null,"errorMessage":"cannot apply int to ${schema.ir.k}","messagePattern":"cannot apply int to (.+?)","errorType":"exception","errorClass":"OmpTypeError","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/zod.ts","lineNumber":160,"sourceCode":"\t\t\t}\n\t\t\tthrow new OmpTypeError(`cannot apply min to ${ir.k}`);\n\t\t},\n\t\tmax(bound: number): ZodLikeSchema<Out> {\n\t\t\tconst ir = schema.ir;\n\t\t\tif (ir.k === \"string\" || ir.k === \"array\") {\n\t\t\t\tlengthBound(\"max\", schema, bound);\n\t\t\t\tconst max = ir.max === undefined ? bound : Math.min(ir.max, bound);\n\t\t\t\treturn next(restrictBase(schema, { ...ir, max }));\n\t\t\t}\n\t\t\tif (ir.k === \"number\") {\n\t\t\t\tif (Number.isNaN(bound)) throw new OmpTypeError(\"number max must not be NaN\");\n\t\t\t\tif (ir.max !== undefined && ir.max <= bound) return next(restrictBase(schema, ir));\n\t\t\t\treturn next(restrictBase(schema, { ...ir, max: bound, xmax: false }));\n\t\t\t}\n\t\t\tthrow new OmpTypeError(`cannot apply max to ${ir.k}`);\n\t\t},\n\t\tint(): ZodLikeSchema<Out> {\n\t\t\tif (schema.ir.k !== \"number\") throw new OmpTypeError(`cannot apply int to ${schema.ir.k}`);\n\t\t\treturn next(restrictBase(schema, { ...schema.ir, int: true }));\n\t\t},\n\t\tpositive(): ZodLikeSchema<Out> {\n\t\t\tif (schema.ir.k !== \"number\") throw new OmpTypeError(`cannot apply positive to ${schema.ir.k}`);\n\t\t\tconst ir = schema.ir;\n\t\t\tif (ir.min !== undefined && ir.min > 0) return next(restrictBase(schema, ir));\n\t\t\treturn next(restrictBase(schema, { ...ir, min: 0, xmin: true }));\n\t\t},\n\t\tnonnegative(): ZodLikeSchema<Out> {\n\t\t\tif (schema.ir.k !== \"number\") throw new OmpTypeError(`cannot apply nonnegative to ${schema.ir.k}`);\n\t\t\treturn this.min(0);\n\t\t},\n\t\tregex(expression: RegExp, message?: string): ZodLikeSchema<Out> {\n\t\t\tif (schema.ir.k !== \"string\") throw new OmpTypeError(`cannot apply regex to ${schema.ir.k}`);\n\t\t\tconst expectation = message ?? `matching ${expression}`;\n\t\t\tconst narrowed = schema.narrow((value, ctx) => {\n\t\t\t\texpression.lastIndex = 0;\n\t\t\t\tconst matches = expression.test(value as string);","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/zod.ts#L142-L178","documentation":"`.int()` constrains a number schema to integers, so it throws when called on a schema whose IR kind is not \"number\". The message interpolates the actual kind. Thrown from `int()` at packages/omptype/src/zod.ts:160.","triggerScenarios":"`t.string().int()`, `t.boolean().int()`, or `.int()` chained onto any non-number schema.","commonSituations":"Renaming/refactoring a field from number to string but keeping the `.int()` call; building schemas generically and mis-targeting the integer constraint; misremembering that omptype has no separate integer type (int is a number modifier).","solutions":["Call .int() only on t.number() schemas","If the value is a numeric string, parse it: t.string().transform(...) or switch the field to t.number().int()","Restructure the chain so .int() sits directly after t.number()"],"exampleFix":"// before\nt.string().int()\n// after\nt.number().int()","handlingStrategy":"type-guard","validationCode":"function canApplyInt(schema: ZodLikeSchema<unknown>): boolean {\n  return schema.ir.k === \"number\";\n}\nif (!canApplyInt(schema)) throw new Error(\"int() requires a number schema\");","typeGuard":"function isNumberSchema(ir: { k: string }): ir is { k: \"number\" } {\n  return ir.k === \"number\";\n}","tryCatchPattern":"try {\n  schema = base.int();\n} catch (err) {\n  if (err instanceof OmpTypeError && err.message.startsWith(\"cannot apply int\")) {\n    throw new Error(\"field must be t.number() to use .int()\");\n  } else throw err;\n}","preventionTips":["Always write t.number().int() as one chain; never spread constraint calls across variables of varying kinds","Remember omptype models integers as a number modifier, not a separate type","If the wire value is a numeric string, parse it before validation instead of constraining the string"],"tags":["schema-builder","type-mismatch","integer"],"backgroundTag":"schema-method-kind-mismatch","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}