Lesson

Apply Schema Custom Refinement with Zod

Enhance your TypeScript validation skills with Zod's refine utility for custom room booking schemas, focusing on date and price validation.

Access
Included
Transcript
Needs source

In this lesson, we dive into the Zod's refine utility, allowing defining more complex schema validation on top of existing schemas and utilities.

Sometimes, we need special validation rules for our applications to work correctly. The refine utility lets developers create their own validation rules. This method's uses a callback to check if the input is valid. We also create meaningful messages when something doesn’t meet the validation rules.

We use a practical example involving a room booking schemawith dueDate and price property refinement.