Exploring Type Safety in Drizzle: Does Zod Enhance or Redundantly Overlap?

I'm new to Drizzle and I'm curious: with Drizzle handling type checking, is there still a benefit to using Zod?
1 Reply
Noahh
Noahh8mo ago
In my experience, yes, but it depends on your use case. Imagine you have a Drizzle schema and a CRUD API for that schema. you can type-check the body all you want, but if a different body is passed at runtime, your code will fail. That's where Zod comes in: checking the body at runtime and validating it's in the correct format. That's why drizzle-zod is so helpful, because you can really easily validate that an object will fit into your Drizzle schema. However, it becomes slightly less helpful when you have APIs that don't match the format of your Drizzle schema. I'd still recommend Zod to check the structures at runtime though :D
Want results from more Discord servers?
Add your server