{"record":{"id":"1495e9653760d44d","repo":"can1357/oh-my-pi","slug":"cannot-apply-partial-to-schema-ir-k","errorCode":null,"errorMessage":"cannot apply partial to ${schema.ir.k}","messagePattern":"cannot apply partial to (.+?)","errorType":"exception","errorClass":"OmpTypeError","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/zod.ts","lineNumber":241,"sourceCode":"\t\t\t\t\tif (!(result instanceof type.errors)) return result;\n\t\t\t\t} catch {\n\t\t\t\t\t// A caught schema is deliberately total, including user refinement/transform exceptions.\n\t\t\t\t}\n\t\t\t\treturn typeof fallback === \"function\" ? (fallback as () => Out)() : fallback;\n\t\t\t});\n\t\t\treturn decorate(caught as Decoratable<Out>, optional);\n\t\t},\n\t\tstrict(): ZodLikeSchema<Out> {\n\t\t\treturn withObjectExtras(\"reject\");\n\t\t},\n\t\tpassthrough(): ZodLikeSchema<Out & Record<string, unknown>> {\n\t\t\treturn withObjectExtras(\"keep\") as ZodLikeSchema<Out & Record<string, unknown>>;\n\t\t},\n\t\tstrip(): ZodLikeSchema<Out> {\n\t\t\treturn withObjectExtras(\"delete\");\n\t\t},\n\t\tpartial(): Out extends object ? ZodLikeSchema<Partial<Out>> : ZodLikeSchema<Out> {\n\t\t\tif (schema.ir.k !== \"object\") throw new OmpTypeError(`cannot apply partial to ${schema.ir.k}`);\n\t\t\tconst props = schema.ir.props.map(prop => ({ ...prop, opt: true }));\n\t\t\treturn next(restrictBase(schema, { ...schema.ir, props })) as Out extends object\n\t\t\t\t? ZodLikeSchema<Partial<Out>>\n\t\t\t\t: ZodLikeSchema<Out>;\n\t\t},\n\t}) as unknown as ZodLikeSchema<Out>;\n}\n\nfunction decorateUnknown(schema: Decoratable<unknown>): ZodLikeSchema<unknown> {\n\treturn decorate(schema);\n}\n\nexport type infer<T> = T extends { readonly _output: infer Out } ? Out : never;\n\ntype SchemaOutput<Schema> = Schema extends { readonly _output: infer Out } ? Out : never;\ntype Shape = Readonly<Record<string, ZodLikeSchema<unknown>>>;\ntype ObjectOutput<S extends Shape> = {\n\t-readonly [K in keyof S as S[K] extends OptionalSchemaMarker ? never : K]: SchemaOutput<S[K]>;","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/zod.ts#L223-L259","documentation":"`.partial()` makes every property of an object schema optional (Zod's `.partial()` semantics); it throws when called on a non-object schema. The message interpolates the actual IR kind. Thrown from `partial()` at packages/omptype/src/zod.ts:241.","triggerScenarios":"`t.string().partial()`, `t.array(...).partial()`, or `.partial()` on schemas produced by unions/primitives — anywhere `schema.ir.k !== \"object\"`.","commonSituations":"Building PATCH-style update schemas where the base type was changed from an object to a union or wrapper; calling .partial() on the wrong variable in a chain; assuming .partial() works on records/arrays like it does in some other libraries.","solutions":["Call .partial() only on schemas built with t.object({...})","For update payloads, ensure the base schema is the object schema before calling .partial()","For arrays/records, there is no .partial() equivalent — model optionality in the element/value schema instead"],"exampleFix":"// before\nconst patchSchema = t.array(t.string()).partial();\n// after\nconst patchSchema = t.object({ name: t.string(), age: t.number() }).partial();","handlingStrategy":"type-guard","validationCode":"function canApplyPartial(schema: ZodLikeSchema<unknown>): boolean {\n  return schema.ir.k === \"object\";\n}\nif (!canApplyPartial(baseSchema)) throw new Error(\"partial() requires an object schema\");","typeGuard":"function isObjectSchema(ir: { k: string }): ir is { k: \"object\" } {\n  return ir.k === \"object\";\n}","tryCatchPattern":"try {\n  patchSchema = baseSchema.partial();\n} catch (err) {\n  if (err instanceof OmpTypeError && err.message.startsWith(\"cannot apply partial\")) {\n    throw new Error(\"base schema must be t.object({...}) for .partial()\");\n  } else throw err;\n}","preventionTips":["Keep the object schema in its own variable before chaining .partial() so unions/wrappers don't sneak in","Build update/PATCH schemas from the object schema, not from transformed or unioned variants","Remember arrays and records have no .partial(); model optionality in elements/values instead"],"tags":["schema-builder","type-mismatch","object"],"backgroundTag":"schema-method-kind-mismatch","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}