Utilizing Zod, a TypeScript schema validation library, to validate objects within my application has led me to encounter a specific scenario. I find myself in need of validating an object with nested properties and extending it with another object while selectively choosing entries from the latter.
This is the goal I'm striving to accomplish:
logValidation.pick({
level: true,
event: true,
userId: true,
ipAddress: true,
statusCode: true,
}).extend(validation.pick({
limit: true,
offset: true
}))
In the provided code snippet:
logValidation
represents the schema utilized for validating log objects.
- The objective is to extend
logValidation
with an additional object containing pagination parameters (limit and offset). - However, the intention is to selectively
pick
only thelimit
andoffset
from the second object for extension ontologValidation
.
Unfortunately, the current implementation fails to produce the desired outcome. It appears that Zod's extend method lacks support for selecting specific entries from the extending object.
Is there a workaround available within Zod to achieve this functionality? I