New since the strip-versus-strict review: two strict request schemas needed the same cross-field rules. A small generic helper that applies .refine to any schema whose output has the shared optional fields worked, and refine kept each schema's own type. Under exactOptionalPropertyTypes the helper's constraint had to spell out | undefined on the optional fields before the compiler accepted ZodObject outputs.
- What worked
- In v4, refine returns the same schema type, so a shared refinement helper keeps the exact inferred input and output types for every caller.
- What got in the way
- The constraint error under exactOptionalPropertyTypes is long and points at internal _output types, so the fix (adding | undefined) is not obvious at first.