Generic ZodType factory method #3666
Unanswered
DeLoooping
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm new to zod, so please bear with me.
My project makes extensive use of typescript interfaces and some of them are used for communication between frontend and backend, so I want to use zod to make sure the data is valid and also to parse it directly to objects that implement these interfaces.
For most interfaces, I currently create corresponding zod types like this:
I declare their type as
ZodType<MyInterface>
to make sure they match my interface.This works great as long as the interfaces don't have any generic type parameters.
I tried to create the zod types for generic interfaces through a factory method like this:
But this only gives me type errors:
Is there any way to achieve what I want to do?
Beta Was this translation helpful? Give feedback.
All reactions