My current challenge involves a Zod shape with multiple keys. I am in need of creating another shape that mirrors the same keys, but with different types. In regular Typescript, this could be achieved with:
type TypeA = {
something1: number
something2: number
...
somethingN: number
}
type TypeB = {
[Property in keyof TypeA]: string
}
By defining the shapes in this way, modifying TypeA automatically updates TypeB whenever keys are added or removed. Is there a method to replicate this functionality using Zod? If so, how can it be implemented?
The code snippet below does not achieve the desired outcome, as it only provides the shape for the first type:
const TypeA = z.object({
something1: z.number(),
something2: z.number(),
...
somethingN: z.number()
)}
type TypeA = z.infer<typeof TypeA>
type TypeB = {
[Property in keyof TypeA]: string
}
// TypeB shape is missing
I am searching for a solution within Zod that allows for iterating over keys and assigning them specific types (or perhaps shapes before being inferred). Is this functionality supported within Zod?