Zod Makes TypeScript Even Better

Поділитися
Вставка
  • Опубліковано 29 вер 2024

КОМЕНТАРІ • 315

  • @hunterbertoson156
    @hunterbertoson156 Рік тому +202

    I would love to see a full tutorial on Zod! Also, an overview on your thoughts of the T3 stack.

  • @jayliu5432
    @jayliu5432 Рік тому

    Showing the form use case for Zod was super helpful. I finally get it!

  • @FatahChan
    @FatahChan Рік тому

    Great video as always, can you make a video about PWA

  • @AndrewDevUA
    @AndrewDevUA Рік тому

    for simple for it's looks awesome!

  • @AutisticThinker
    @AutisticThinker Рік тому

    Looks like the Yup package. I abandoned Yup for just using Formik with custom regex validation.

  • @olegsbk3562
    @olegsbk3562 Рік тому

    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

  • @arunavabanerjee6103
    @arunavabanerjee6103 Рік тому +35

    Hey Kyle, thanks for the video, zod seems super cool and I'd really like if could make a tutorial on it

  • @odisclemons9700
    @odisclemons9700 Рік тому +6

    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

  • @akhnldc9870
    @akhnldc9870 Рік тому +3

    Isn't it the same as yup?

  • @rand0mtv660
    @rand0mtv660 Рік тому +17

    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 :)

  • @daminipandey6490
    @daminipandey6490 Рік тому +2

    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 .

  • @papadavis47
    @papadavis47 Рік тому +11

    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!

  • @ReconNite
    @ReconNite Рік тому +13

    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.

    • @BinaryReader
      @BinaryReader Рік тому +1

      Try TypeBox, it's based on industry standards and it's also 300x faster than Zod.

  • @MultiPoiu
    @MultiPoiu Рік тому +5

    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

  • @akashsinha5148
    @akashsinha5148 Рік тому +8

    That would be wonderful 👍 please do a full tutorial. As your tutorials are small and feature packed.

  • @TroenderTass
    @TroenderTass Рік тому +1

    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.

  • @stanislauyan3204
    @stanislauyan3204 Рік тому +1

    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

  • @nmanikiran
    @nmanikiran Рік тому +5

    would love to see a full tutorial on Zod! And also please compare with Joi, ajv, zod

    • @BinaryReader
      @BinaryReader Рік тому

      Comparing Zod to Ajv would be embarrassing....for Zod >_>

  • @anatolydyatlov963
    @anatolydyatlov963 Рік тому +3

    Yep, I've been using it for the past few months and it's a must-have for schemaless dbs.

  • @j4yd34d5
    @j4yd34d5 Рік тому +11

    Zod is indestructible. (only true gamers will get this)

    • @MichelAngeIo
      @MichelAngeIo Рік тому +1

      So even if you have etheral code, you’re good to go

  • @jordanebelanger3918
    @jordanebelanger3918 Рік тому +2

    Just use ajv and json-schema

  • @souvlaki42
    @souvlaki42 Рік тому +5

    Very cool library. I really like the idea of a tutorial about it.

  • @boian-inavov
    @boian-inavov Рік тому +17

    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 👏

    • @BinaryReader
      @BinaryReader Рік тому

      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.

  • @abdirahmann
    @abdirahmann Рік тому +3

    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 :)

  • @deveshrawool6035
    @deveshrawool6035 Рік тому +4

    Could have used some other additional info as to why is it better than other validation schema libraries for instance like Yup.

    • @valentynlugovyi4789
      @valentynlugovyi4789 Рік тому +1

      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.

  • @remccs16
    @remccs16 Рік тому +5

    This is great, thank you Kyle! I would most certainly watch a full tutorial on Zod!

  • @ColinRichardson
    @ColinRichardson Рік тому +3

    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.

  • @josecongo9453
    @josecongo9453 Рік тому +1

    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

  • @shrunkensimon
    @shrunkensimon Рік тому +2

    Kneel before Zod

  • @samuelwittlinger7790
    @samuelwittlinger7790 Рік тому +4

    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.

  • @JasonLayton
    @JasonLayton 10 місяців тому +1

    Implementing Zod has been one of the worst decisions that my team has made. We all hate it.

    • @LEDACOFFICIAL
      @LEDACOFFICIAL 9 місяців тому

      why tho 😂

    • @JasonLayton
      @JasonLayton 9 місяців тому

      @@LEDACOFFICIALbetween Zod and react hook forms, they add enormous complexity and rigidity to the code.
      I also find the debugging experience to be poor.

    • @al-doori2392
      @al-doori2392 8 місяців тому

      Same here

  • @mind_of_a_darkhorse
    @mind_of_a_darkhorse Рік тому +2

    I am intrigued! So, please make a tutorial on this game-changing way of doing things!

  • @pomprocks
    @pomprocks Рік тому +3

    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.

  • @nomiscph
    @nomiscph Рік тому +2

    In angular they have forms with full typescript support 🎉 for everyone working with angular

  • @martinpenev6750
    @martinpenev6750 Рік тому +1

    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?

  • @LasgCe
    @LasgCe Рік тому +2

    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

  • @genc_emekli
    @genc_emekli Рік тому +1

    Hello. please do a full tutorial. I have already started to use zod. Many thanks.

  • @yohanneskindu8794
    @yohanneskindu8794 Рік тому +1

    It is cool, very similar to Joi.

  • @sujoydutta920
    @sujoydutta920 Рік тому +3

    That would be really great to have a tutorial on Zod

  • @oswaldosoto4500
    @oswaldosoto4500 Рік тому +1

    would be nice have a zod tutorial for advanced user/passwords forms.

  • @dhaivathlal4870
    @dhaivathlal4870 Рік тому +1

    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

  • @NewHellz-
    @NewHellz- Рік тому

    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??

  • @saimrgondal2360
    @saimrgondal2360 6 місяців тому

    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.

  • @ganeshborade3706
    @ganeshborade3706 Рік тому

    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

  • @SeraphicRav
    @SeraphicRav Рік тому

    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.

  • @TheLongestConfidence
    @TheLongestConfidence Рік тому

    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.

  • @arian5126
    @arian5126 Рік тому +3

    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.

    • @AmanSingh-px5if
      @AmanSingh-px5if Рік тому +1

      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.

    • @arian5126
      @arian5126 Рік тому +5

      @@AmanSingh-px5if you don't have to use all built-in modules. The compiler removes unused modules from the bundle.

  • @oleksandrluchytskyi6867
    @oleksandrluchytskyi6867 Рік тому +2

    Yes, please a video with most common recipes will be good to have 🤩

  • @diegomiyt
    @diegomiyt Рік тому

    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 )

  • @andreas_bergstrom
    @andreas_bergstrom Рік тому

    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?

  • @alemswazzu
    @alemswazzu Рік тому

    You absolutely missed a great opportunity to use the line from Superman. "Kneel before Zod", especially if it's that good.

  • @shivamsahil3660
    @shivamsahil3660 Рік тому +1

    Hmm this seems more of a form validation library rather than improvement on typescript. Thanks a lot Kyle ❤️

  • @tarsala1995
    @tarsala1995 Рік тому

    Ok and what about Yup? It's looks very similar and some good libs like Formik are supporting Yup out of the box

  • @ccrsxx
    @ccrsxx Рік тому

    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.

  • @codeNameMoose907
    @codeNameMoose907 Рік тому +1

    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! 😊

  • @tbcfrankee
    @tbcfrankee Рік тому

    Was using yup, ajv, validator... once I looked at Zod, I never turned back!

  • @jeffjeff5719
    @jeffjeff5719 Рік тому

    Wtf is zod, jesus everyday i hear about some 3 4 new languages and technology since i have started learn coding

  • @deendayal2309
    @deendayal2309 Місяць тому +1

    Dg

  • @ellaa_nashwara
    @ellaa_nashwara Рік тому

    Please checkout *typescript-json* which supposed to be 1000x faster

  • @DaviddeKloet
    @DaviddeKloet Рік тому

    "String must contain at least 5 character(s)" is honestly a pretty ugly error message compared to "Name must contain at least 5 characters"

  • @fotoflo
    @fotoflo Рік тому +1

    Thank you for this great video! Wanted to note that Zod also offers a little bit of API around error messages as well.

  • @Humperpump
    @Humperpump Рік тому

    7 months and not a single reference to "KNEEL BEFORE ZOD!"

  • @kerembo12
    @kerembo12 Рік тому

    Hi,
    could you give us a Tutorial about BDD testing? Would appreciate that

  • @arryaz051
    @arryaz051 Рік тому +1

    Great tool, I use it a lot in NodeJS HTTP APIs to validate requests to the server and get the TypeScript type too.

  • @abhimn7856
    @abhimn7856 Рік тому

    I don't understand the need for this. You can use something like React Hook Form for this

  • @skyzane2735
    @skyzane2735 10 місяців тому

    What about Valibot? I hear everyone talking about Valibot would now be better than Zod.

  • @bretlyy
    @bretlyy Рік тому

    What’s the best way to learn to JavaScript/programming?

  • @MrMkSm
    @MrMkSm Рік тому +1

    Looks like pydantic (Python) for Typescript

  • @kylekirby6424
    @kylekirby6424 Рік тому

    Ever heard of io-ts? Yeah … I don’t think zod is first to market by a long shot.

  • @phill13able
    @phill13able Рік тому

    I thought TypeScript wasn't supported by browsers

  • @31redorange08
    @31redorange08 Рік тому

    Thumbnail: "I Love ZOD 🤔"
    What is that supposed to mean?

  • @AliAkbarAzizi
    @AliAkbarAzizi Рік тому

    acutally yup also do infer type too. I don't see what is the point of migration from yup to zod

  • @mihinov
    @mihinov Рік тому

    oh, the guys were able to implement part of the work of angular validators 😂

  • @NikesDarkslayer
    @NikesDarkslayer Рік тому

    you forgot to metion that zod also have a refine feature where you create your own validation for each section =)

  • @pieter5466
    @pieter5466 Рік тому

    Zod looks exactly like every software library should.

  • @kirrttiraj
    @kirrttiraj 10 місяців тому

    I am struggling to validate an image that I am taking from the user. Can someone help

  • @tonyg_nerd
    @tonyg_nerd Рік тому +1

    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.

    • @tonyg_nerd
      @tonyg_nerd Рік тому

      Looks like Zod is the winner with Hook Forms.

  • @davidconnelly
    @davidconnelly Рік тому

    Kneel before Zod!

  • @jonasboardwalker
    @jonasboardwalker Рік тому

    Is it better than Yup? Will it work with react-hook-form?

  • @UwU-dx5hu
    @UwU-dx5hu 11 місяців тому

    Why dont people understand zod has nothing to do with typescript 😑😑

  • @phill13able
    @phill13able Рік тому

    How are you able to make TypeScript to run in the browser???

  • @Pycckuu_Ka3ax
    @Pycckuu_Ka3ax Рік тому

    I would like to see tutorial which include how to make custom error messages

  • @SpaceGravy
    @SpaceGravy Рік тому

    A comparison with yup would be appreciated!

  • @darkerisbetter8699
    @darkerisbetter8699 Рік тому +5

    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).

    • @z-aru
      @z-aru Рік тому

      You could use .refine() or .superRefine(), it's amazing stuff

  • @skverskk
    @skverskk Рік тому

    In your opinion, how does Zod compare to yup? Nice tutorial.

  • @alihamoud6863
    @alihamoud6863 Рік тому

    You are the best not zod, Iam joking 😄
    All love kyle❤

  • @merotuts9819
    @merotuts9819 Рік тому

    Oh man I love Zod, much better than Joi or Yup IMO.

  • @anuragpal02
    @anuragpal02 Рік тому +4

    Zod is insane, I used it for API response validation, great features.

  • @ChasingShadowsz
    @ChasingShadowsz Рік тому

    Dark mode for us night watchers please!

  • @VirgilShisler
    @VirgilShisler 17 днів тому

    947 Schowalter Junction

  • @paschalokafor9043
    @paschalokafor9043 10 місяців тому

    Can I use Zod in place of Yup when using formik?

  • @DesmoSaze
    @DesmoSaze Рік тому

    what is this kind of notation : "form?.addEventListener(...)" or "nameInput?.value" with questionmark followed by dot ?

    • @DesmoSaze
      @DesmoSaze Рік тому

      if i understand, you check if the form or the variable exist and if it does, follow with what commes after the question mark ?

  • @none0n
    @none0n Рік тому

    Another Js boys shinning tool 🤦🏾🤦🏾🤦🏾

  • @vizunaldth
    @vizunaldth Рік тому

    Kyle - full tut like you did on prisma would be nice to watch

  • @wayneswildworld
    @wayneswildworld Рік тому

    So this is mainly for forms and user input correct???

  • @forresto
    @forresto Рік тому

    0:43 Don't put a minimum length on a name field though. "O" is a name.

  • @b5fw6jg7
    @b5fw6jg7 Рік тому +2

    What about yup + React Hook Form?

    • @Marcot348
      @Marcot348 Рік тому

      I was wondering the same. To me this seems just like yup at first sight 😅

  • @erkeliwood6037
    @erkeliwood6037 Рік тому

    What's the difference between this and formik?

  • @belkocik
    @belkocik Рік тому +1

    Isn't it better to use yup? + It supports formik