{"record":{"id":"3503d1fd56e73a7d","repo":"can1357/oh-my-pi","slug":"cannot-apply-min-to-ir-k","errorCode":null,"errorMessage":"cannot apply min to ${ir.k}","messagePattern":"cannot apply min to (.+?)","errorType":"exception","errorClass":"OmpTypeError","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/zod.ts","lineNumber":143,"sourceCode":"\t\t\t\terror: {\n\t\t\t\t\tmessage: result.summary,\n\t\t\t\t\tissues: result.map(issue => ({ path: [...issue.path], message: issue.problem })),\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t\tmin(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(\"min\", schema, bound);\n\t\t\t\tconst min = ir.min === undefined ? bound : Math.max(ir.min, bound);\n\t\t\t\treturn next(restrictBase(schema, { ...ir, min }));\n\t\t\t}\n\t\t\tif (ir.k === \"number\") {\n\t\t\t\tif (Number.isNaN(bound)) throw new OmpTypeError(\"number min must not be NaN\");\n\t\t\t\tif (ir.min !== undefined && ir.min >= bound) return next(restrictBase(schema, ir));\n\t\t\t\treturn next(restrictBase(schema, { ...ir, min: bound, xmin: false }));\n\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 }));","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/zod.ts#L125-L161","documentation":"The zod-compat `.min()` method only supports string, array, and number schemas; applying it to any other kind throws `cannot apply min to <kind>` (kind = the schema's IR kind, e.g. `boolean`, `object`, `null`, `union`). Zod's `.min()` exists mainly on strings/numbers/arrays; omptype's compat layer enforces that surface.","triggerScenarios":"`z.boolean().min(0)`, `z.object({...}).min(1)`, `.min()` on a literal/null/union schema built through the compat layer.","commonSituations":"Generic helper functions applying `.min()` to whichever schema they receive; refactoring a field from string to boolean while keeping `.min()` chained; zod code migrated from third-party plugins where `.min()` existed on more types.","solutions":["Remove the `.min()` call from non-string/array/number schemas — it has no meaning there.","For objects, express the constraint differently (e.g. refine on key count) rather than `.min()`.","In generic code, narrow by kind before applying: only call `.min()` when the schema is a string/array/number schema."],"exampleFix":"// before\nconst enabled = z.boolean().min(0); // throws\n// after\nconst enabled = z.boolean();","handlingStrategy":"type-guard","validationCode":"// apply min only to supported kinds\nconst k = (schema as unknown as { ir: { k: string } }).ir.k;\nif (!['string', 'array', 'number'].includes(k)) throw new Error(`cannot apply min to ${k}`);","typeGuard":"function supportsMin(s: ZodLikeSchema<unknown>): boolean {\n  const k = (s as unknown as { ir: { k: string } }).ir.k;\n  return k === \"string\" || k === \"array\" || k === \"number\";\n}","tryCatchPattern":"try {\n  const bounded = maybeSchema.min(1);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('cannot apply min to')) {\n    return maybeSchema; // kind doesn't support min — skip the constraint\n  }\n  throw err;\n}","preventionTips":["Only chain .min()/..max() on string, array, or number schemas.","Type helper parameters to the supported schema kinds so misuse fails at compile time.","Remove min/max chains after refactoring a field's type to a non-bounded kind."],"tags":["omptype","zod-compat","unsupported-operation","schema-construction"],"backgroundTag":"unsupported-schema-method","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}