Theo's Typesafe CultTTC
Theo's Typesafe Cult17mo ago
6 replies
Mugetsu

Use Zod schema after parse & transform as a new schema

I am looking how I could handle from validation with one schema so it can be used on the ReactHookForm zod resolver and tRPC input validation.

lets say my form accepts two values
const schema = z.object({
    name: z.string(),
    bir: z.object({
        value: z.string(),
        label: z.string(),
    }).transform(val => val.value),

})

type SchemaT = z.infer<typeof asd>

const asdzz: SchemaT = {
    bir: 'asd',name: 'as'
} 


schema is a parser for client form input which I would like to use resulting type of that schema as a new schema for tRPC input validation. Can I do this somehow? Or my bet is just don't do the transform and use that schema both on client and backend and on backend extract needed fields and do further processing. This will be simpler but unnecessary bloat of data payload would be then sent to the server
Was this page helpful?