Yeah Zod is cool, but it also kinda depends what you are doing IMO. If you use Zod to validate endpoints that you create with tRPC, then it seems to be great. If you use it for validating forms on frontend with react-hook-form, then yup might just be slightly better. That's at least from my personal experience comparing these two. yup also has a nice Typescript experience and the infer type from schema like the z.infer you shown here. Zod isn't the first schema validation library to utilize Typescript, but it seems people act like it is :)
Well done, Kyle. I have heard of zod, but I have not used it yet. I appreciate this concise video of what it is. A full tutorial with a React Typescript project would be great. Thanks for your work!
The problem I ran into with zod was that, not only was it super slow compared to other validators it was also very limiting as to what could be checked, or what could be coerced from one value to another. Although I still use it on some projects, I started to move over to superstruct for my more recent projects as it allows me to define custom refinements/coercions/types with little trouble. Of course this means that you lose the "built-in" or modular aspect of zod, superstruct makes it a lot easier for targeted validation.
Erf, i'm sticking to AJV when doing api-first design and reusable component, because jsonSchema, even if it is a bit more tedious, it is reusable in all language, and can serve as first class API doc with swagger (jsonSchema are almost 100% compatible to swagger) And DTO with annotation are more readable for other stuff, I then use class-validator
God. Stop adding libraries to do basic stuff. This is gonna bloat your application for nothing but you being lazy. Stop creating libraries to solve simple problems that don't need them.
Inferring the type from validation schema is very bad idea. Type is what defines your data and validation schema must satisfy the type. Also I see no extra bonuses in this in comparison with yup
I love how Zod has picked up popularity lately. I’ve been using it it for a while and it’s been amazing! You just forget about the cumbersome validation part and focus on building your business logic. Also the way it’ll give you a ready made object in the way you’d been expecting it is just god sent! Glad that more people are covering it 👏
Zod is no different to Yup, in fact, Zod is basically a clone of Yup with better static typing. Also, Zod is incredibly slow. Compare it to industry standard validators and it's like 300x slower to validate anything. You shouldn't be using Zod on the server side (it's that bad) The hype around Zod is real, but that doesn't make it good. It's just social media marketing and online influencers pushing it.
OMG OMG OMG OMG please do a full tutorial on this one, this is going to simplify my data validation logic on my node server, i also just migrated everything to ts yesterday, how awesome, also, i checked out express-validator and i didn't like how it did validation using middlewares and stuff soo this is a GOD send. Thanks GOD and thanks to you too for letting us know. love ya :)
Exectly, it is a lot more useful to comper with Yup! I usually use Yup in my projects, I am used to it, and so far not reason provided to switch to Zod. Now I will have to do my own research to comper them.
The problem I found with Zod is the transforms. It starts to blur the edges between validating and parsing. But my manager found a good library (I don't remember it's name for the top of my head) which uses the TS types and makes it a type validator at compile time, rather than runtime, using vite plugins. It seems like a better suit for us as we already have the types setup, rather than using Zod to Infer the types.
Please do a full Tuturial. I have a question, with zod do I still need create Interface(TS) for static checking? How can I reuse zod in multiple component(I thinking i react component). Thank you
Looks pretty good, personally I created a validator based on Joi which returns the object you are validating typecasted as the object type your validation schema is describing, which is a little more convenient than having to call infer every time.
@@LEDACOFFICIALbetween Zod and react hook forms, they add enormous complexity and rigidity to the code. I also find the debugging experience to be poor.
You should show it with the same validation messages that your if/else validation has. Often certain messages need to be used, not just whatever messages your validation library produces.
I remember watching the video 2 days ago and thinking, why would I ever need this .. Well, today I needed to create a very complex form validation and I gotta say, Zod is doing a great job so far
I'm about to do my first typescript form validation without any framework hence no framework provided form validation methods. This video just dropped right on time
I'd like a video comparing this with other form validation libs such as Joi. I;ve used Joi in the past and Im really curious to see if zod offers better usability. Thanks. Love your videos.
Hi I need to convert my html&css animation to mp4 video with 60 fps 1080 p and transparent video and I don't know anything about javascript, node.js , javascript libraries please could you make a detailed video on this topic? Your help will be highly appreciated. Because I don't know anything about coding, please make step by step guide. I only know css and html and I already created animation I just need to convert it to video.
Рік тому
I do not see the benefits with TypeScript. Because the TSC already ensures that stuff at compiletime which Zod does at runtime. #Update: well regarding the form validation you might have point. i use regularly angular which already provide form validation. but if you don't any major framework, this might be quite handy to have
What about sinclair/Typebox? It is 5 times more downloaded than Zod people are talking about, 2 times more than Joi that I am using but lack type inferring.
Zod is not a functional solution to schema validation. The first clue is the chaining API. The second is the result type, which can't be composed without requiring that your functions handle the { success, error } return object. If you want an actual functional solution for this problem, you're going to want to look into io-ts. Learning io-ts (and fp-ts, which you'll really want to use to get the full benefits) definitely has a learning curve up front, but the backend advantages pay off in a big way.
Great, exactly what I needed in the right time for a React project but for someone who's worked with Angular FormBuilder (which is a built-in module), you'd know how Angular is underrated.
I don't get the fuzz around Zod. We had joi and other validators for years? Wether it's a http request, parsed XML-file or data returned from a DB something has most often already parsed the data according to a schema anyway?
Why tf would I want to add this on top of typescript. Typescript is already good enough. Not to mention this will add another boilerplate code to your type. I'm definitely not using this lol.
Awesome! I never heard of Zod! But more importantly... hope you feel much better soon Kyle! Your followers will be here waiting; we won't ever leave you. Thanks for everything you do! Sending you and yours super healthy and happy healing vibes, Buddy! 😊
Kyle, thanks for this. I'm tooling up for projects with React, MUI, Redux, and have been looking into Formik which validates (primarily) with Yup. I'm not loving the Formik/Yup side, so it'll be nice to give Zod a spin, especially since it's TS-first, as am I. As someone else noted, my primary questions will be about custom rules, field/field comparisons, and async/sync server validations. Zod MUST perform here or I need to go with an established standard.
Based on a quick glance, there seems to be some serious limitations around conditional validation (i.e. range of values for fieldA can be constrained based on another fieldB).
I would love to see a full tutorial on Zod! Also, an overview on your thoughts of the T3 stack.
I second this
I third the t3 stack
I 4th the T3 stack
I 6th this with Async validation with Zod (like unique username).
i 7th love to see this
Showing the form use case for Zod was super helpful. I finally get it!
Great video as always, can you make a video about PWA
for simple for it's looks awesome!
Looks like the Yup package. I abandoned Yup for just using Formik with custom regex validation.
The zod is very interesting, but how do you validate a conditional rendering of the required field in object on it? So far it doesn't work well
Hey Kyle, thanks for the video, zod seems super cool and I'd really like if could make a tutorial on it
If you truly love Zod then KNEEL before Zod. Note: I'm 100% sure no one on the internet thought to make that exact same joke
Isn't it the same as yup?
I was thinking the same
Yeah Zod is cool, but it also kinda depends what you are doing IMO. If you use Zod to validate endpoints that you create with tRPC, then it seems to be great. If you use it for validating forms on frontend with react-hook-form, then yup might just be slightly better. That's at least from my personal experience comparing these two. yup also has a nice Typescript experience and the infer type from schema like the z.infer you shown here. Zod isn't the first schema validation library to utilize Typescript, but it seems people act like it is :)
Hey. I'm just curious to know if it's possible to chain multiple regex expressions for the same input field and display different error messages .
@@victor_productions Siuuuuuuuuu
Well done, Kyle. I have heard of zod, but I have not used it yet. I appreciate this concise video of what it is. A full tutorial with a React Typescript project would be great. Thanks for your work!
The problem I ran into with zod was that, not only was it super slow compared to other validators it was also very limiting as to what could be checked, or what could be coerced from one value to another. Although I still use it on some projects, I started to move over to superstruct for my more recent projects as it allows me to define custom refinements/coercions/types with little trouble. Of course this means that you lose the "built-in" or modular aspect of zod, superstruct makes it a lot easier for targeted validation.
Try TypeBox, it's based on industry standards and it's also 300x faster than Zod.
Erf, i'm sticking to AJV when doing api-first design and reusable component, because jsonSchema, even if it is a bit more tedious, it is reusable in all language, and can serve as first class API doc with swagger (jsonSchema are almost 100% compatible to swagger)
And DTO with annotation are more readable for other stuff, I then use class-validator
Makes sense. JSON portability FTW
That would be wonderful 👍 please do a full tutorial. As your tutorials are small and feature packed.
God. Stop adding libraries to do basic stuff. This is gonna bloat your application for nothing but you being lazy. Stop creating libraries to solve simple problems that don't need them.
Inferring the type from validation schema is very bad idea. Type is what defines your data and validation schema must satisfy the type. Also I see no extra bonuses in this in comparison with yup
would love to see a full tutorial on Zod! And also please compare with Joi, ajv, zod
Comparing Zod to Ajv would be embarrassing....for Zod >_>
Yep, I've been using it for the past few months and it's a must-have for schemaless dbs.
Zod is indestructible. (only true gamers will get this)
So even if you have etheral code, you’re good to go
Just use ajv and json-schema
Very cool library. I really like the idea of a tutorial about it.
I love how Zod has picked up popularity lately. I’ve been using it it for a while and it’s been amazing! You just forget about the cumbersome validation part and focus on building your business logic. Also the way it’ll give you a ready made object in the way you’d been expecting it is just god sent! Glad that more people are covering it 👏
Zod is no different to Yup, in fact, Zod is basically a clone of Yup with better static typing. Also, Zod is incredibly slow. Compare it to industry standard validators and it's like 300x slower to validate anything. You shouldn't be using Zod on the server side (it's that bad)
The hype around Zod is real, but that doesn't make it good. It's just social media marketing and online influencers pushing it.
OMG OMG OMG OMG please do a full tutorial on this one, this is going to simplify my data validation logic on my node server, i also just migrated everything to ts yesterday, how awesome, also, i checked out express-validator and i didn't like how it did validation using middlewares and stuff soo this is a GOD send. Thanks GOD and thanks to you too for letting us know. love ya :)
Could have used some other additional info as to why is it better than other validation schema libraries for instance like Yup.
Exectly, it is a lot more useful to comper with Yup! I usually use Yup in my projects, I am used to it, and so far not reason provided to switch to Zod. Now I will have to do my own research to comper them.
This is great, thank you Kyle! I would most certainly watch a full tutorial on Zod!
The problem I found with Zod is the transforms. It starts to blur the edges between validating and parsing.
But my manager found a good library (I don't remember it's name for the top of my head) which uses the TS types and makes it a type validator at compile time, rather than runtime, using vite plugins. It seems like a better suit for us as we already have the types setup, rather than using Zod to Infer the types.
can you share what library you are using ?
Please do a full Tuturial. I have a question, with zod do I still need create Interface(TS) for static checking? How can I reuse zod in multiple component(I thinking i react component).
Thank you
Kneel before Zod
Looks pretty good, personally I created a validator based on Joi which returns the object you are validating typecasted as the object type your validation schema is describing, which is a little more convenient than having to call infer every time.
Implementing Zod has been one of the worst decisions that my team has made. We all hate it.
why tho 😂
@@LEDACOFFICIALbetween Zod and react hook forms, they add enormous complexity and rigidity to the code.
I also find the debugging experience to be poor.
Same here
I am intrigued! So, please make a tutorial on this game-changing way of doing things!
You should show it with the same validation messages that your if/else validation has. Often certain messages need to be used, not just whatever messages your validation library produces.
In angular they have forms with full typescript support 🎉 for everyone working with angular
Hi Kyle
Thx for showing us Zod, I really think it’s supercool!
I was wondering: Which validation library have you been using before Zod?
I remember watching the video 2 days ago and thinking, why would I ever need this ..
Well, today I needed to create a very complex form validation and I gotta say, Zod is doing a great job so far
Hello. please do a full tutorial. I have already started to use zod. Many thanks.
It is cool, very similar to Joi.
That would be really great to have a tutorial on Zod
would be nice have a zod tutorial for advanced user/passwords forms.
I'm about to do my first typescript form validation without any framework hence no framework provided form validation methods. This video just dropped right on time
hey there, may i ask something ??
Is there possible if to create progress bar, with numered inside can change automatically with the date i want to??
I'd like a video comparing this with other form validation libs such as Joi. I;ve used Joi in the past and Im really curious to see if zod offers better usability. Thanks.
Love your videos.
Hi I need to convert my html&css animation to mp4 video with 60 fps 1080 p and transparent video and I don't know anything about javascript, node.js , javascript libraries please could you make a detailed video on this topic? Your help will be highly appreciated. Because I don't know anything about coding, please make step by step guide. I only know css and html and I already created animation I just need to convert it to video.
I do not see the benefits with TypeScript. Because the TSC already ensures that stuff at compiletime which Zod does at runtime.
#Update: well regarding the form validation you might have point. i use regularly angular which already provide form validation. but if you don't any major framework, this might be quite handy to have
What about sinclair/Typebox? It is 5 times more downloaded than Zod people are talking about, 2 times more than Joi that I am using but lack type inferring.
Zod is not a functional solution to schema validation. The first clue is the chaining API. The second is the result type, which can't be composed without requiring that your functions handle the { success, error } return object. If you want an actual functional solution for this problem, you're going to want to look into io-ts.
Learning io-ts (and fp-ts, which you'll really want to use to get the full benefits) definitely has a learning curve up front, but the backend advantages pay off in a big way.
Great, exactly what I needed in the right time for a React project but for someone who's worked with Angular FormBuilder (which is a built-in module), you'd know how Angular is underrated.
and exactly why react is so popular, not every project will need all the built in modules or even of the type that are baked in.
@@AmanSingh-px5if you don't have to use all built-in modules. The compiler removes unused modules from the bundle.
Yes, please a video with most common recipes will be good to have 🤩
Can i use zod to 'autommaper' ( like automapper from c# ) for convert one type to another? (Ex: IUserResponse from api to IUserState to use in React )
I don't get the fuzz around Zod. We had joi and other validators for years? Wether it's a http request, parsed XML-file or data returned from a DB something has most often already parsed the data according to a schema anyway?
You absolutely missed a great opportunity to use the line from Superman. "Kneel before Zod", especially if it's that good.
Hmm this seems more of a form validation library rather than improvement on typescript. Thanks a lot Kyle ❤️
Ok and what about Yup? It's looks very similar and some good libs like Formik are supporting Yup out of the box
Why tf would I want to add this on top of typescript. Typescript is already good enough. Not to mention this will add another boilerplate code to your type.
I'm definitely not using this lol.
Awesome! I never heard of Zod! But more importantly... hope you feel much better soon Kyle! Your followers will be here waiting; we won't ever leave you. Thanks for everything you do! Sending you and yours super healthy and happy healing vibes, Buddy! 😊
Was using yup, ajv, validator... once I looked at Zod, I never turned back!
Wtf is zod, jesus everyday i hear about some 3 4 new languages and technology since i have started learn coding
Dg
Please checkout *typescript-json* which supposed to be 1000x faster
"String must contain at least 5 character(s)" is honestly a pretty ugly error message compared to "Name must contain at least 5 characters"
Thank you for this great video! Wanted to note that Zod also offers a little bit of API around error messages as well.
7 months and not a single reference to "KNEEL BEFORE ZOD!"
Hi,
could you give us a Tutorial about BDD testing? Would appreciate that
Great tool, I use it a lot in NodeJS HTTP APIs to validate requests to the server and get the TypeScript type too.
I don't understand the need for this. You can use something like React Hook Form for this
What about Valibot? I hear everyone talking about Valibot would now be better than Zod.
What’s the best way to learn to JavaScript/programming?
Looks like pydantic (Python) for Typescript
Ever heard of io-ts? Yeah … I don’t think zod is first to market by a long shot.
I thought TypeScript wasn't supported by browsers
Thumbnail: "I Love ZOD 🤔"
What is that supposed to mean?
acutally yup also do infer type too. I don't see what is the point of migration from yup to zod
oh, the guys were able to implement part of the work of angular validators 😂
you forgot to metion that zod also have a refine feature where you create your own validation for each section =)
Zod looks exactly like every software library should.
I am struggling to validate an image that I am taking from the user. Can someone help
Kyle, thanks for this. I'm tooling up for projects with React, MUI, Redux, and have been looking into Formik which validates (primarily) with Yup. I'm not loving the Formik/Yup side, so it'll be nice to give Zod a spin, especially since it's TS-first, as am I. As someone else noted, my primary questions will be about custom rules, field/field comparisons, and async/sync server validations. Zod MUST perform here or I need to go with an established standard.
Looks like Zod is the winner with Hook Forms.
Kneel before Zod!
Is it better than Yup? Will it work with react-hook-form?
Why dont people understand zod has nothing to do with typescript 😑😑
How are you able to make TypeScript to run in the browser???
I would like to see tutorial which include how to make custom error messages
A comparison with yup would be appreciated!
Based on a quick glance, there seems to be some serious limitations around conditional validation (i.e. range of values for fieldA can be constrained based on another fieldB).
You could use .refine() or .superRefine(), it's amazing stuff
In your opinion, how does Zod compare to yup? Nice tutorial.
You are the best not zod, Iam joking 😄
All love kyle❤
Oh man I love Zod, much better than Joi or Yup IMO.
Zod is insane, I used it for API response validation, great features.
Dark mode for us night watchers please!
947 Schowalter Junction
Can I use Zod in place of Yup when using formik?
what is this kind of notation : "form?.addEventListener(...)" or "nameInput?.value" with questionmark followed by dot ?
if i understand, you check if the form or the variable exist and if it does, follow with what commes after the question mark ?
Another Js boys shinning tool 🤦🏾🤦🏾🤦🏾
Kyle - full tut like you did on prisma would be nice to watch
So this is mainly for forms and user input correct???
0:43 Don't put a minimum length on a name field though. "O" is a name.
What about yup + React Hook Form?
I was wondering the same. To me this seems just like yup at first sight 😅
What's the difference between this and formik?
Isn't it better to use yup? + It supports formik