tRPCttRPC
Powered by
fengF
tRPC•2y ago•
4 replies
feng

How to use output validation for dates? (Zod, SuperJSON)

I am trying to add output validation with zod, and my defined zod schema. I have currently set up superJson to transform my objects to and from, so that it can also do date transformation.

If I add .output(ZodSchemaObject) it throws
Expected date, received string
Expected date, received string


This is becuse the ZodSchemaObject has a date in it.

However I'm not sure how to make it so that it does the validation BEFORE the SuperJSON has had a chance to transform to string (is this correct?) to send to the client.

Has anyone else had any success with this? Only solution now is to remove output validation and risk returning too much data
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Zod Output validation failed
JohnyJJohny / ❓-help
9mo ago
Migrating to use Superjson
MayhulMMayhul / ❓-help
14mo ago
SuperJSON not tranforming dates in edge runtime
EmilEEmil / ❓-help
14mo ago
How to make trpc output return strings and not dates
TaylorFayTTaylorFay / ❓-help
3y ago