You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to somehow do transform on the fields conditionally?
Something alongside
constschema=<Textends'UI'|'API'>(type: T)=>z.object({value: z.string()}).transform((value)=>(type==='UI' ? value : value.value)).nullable();typeSchemaReturnType<Textends'UI'|'API'>=z.infer<ReturnType<typeofschema<T>>>;typeA=SchemaReturnType<'UI'>;typeB=SchemaReturnType<'API'>;
A type should be { value: string } | null
B type should be string | null
But both are {value: ZodString["_output"]} | string | null in this case.
I want to be able to have one schema that I can use on the frontend and backend validation but on the backend after parsing I want flat value where on the frontend I need object
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Is it possible to somehow do transform on the fields conditionally?
Something alongside
A type should be { value: string } | null
B type should be string | null
But both are
{value: ZodString["_output"]} | string | null
in this case.I want to be able to have one schema that I can use on the frontend and backend validation but on the backend after parsing I want flat value where on the frontend I need object
Beta Was this translation helpful? Give feedback.
All reactions