Zod Goes Where TypeScript Can't

Поделиться
HTML-код
  • Опубликовано: 29 сен 2024
  • Zod is dope, please use it
    (Sorry for the old camera video - have like 5 more of these to burn through and then we'll be all in on the 4k)
    #t3stack #fullstack #webdevelopment
    ALL MY VIDEOS ARE POSTED EARLY ON PATREON / t3dotgg
    Everything else (Twitch, Twitter, Discord & my blog): t3.gg/links

Комментарии • 185

  • @TomDoesTech
    @TomDoesTech Год назад +206

    My favourite feature of Zod is that it, by default (configurable), will remove fields from an object that aren't defined in the schema. So it makes it safe to pass a parsed object straight into your DB without having to pick or omit fields.

    • @semyaza555
      @semyaza555 Год назад +14

      How tf did I not know that.

    • @GiveMeSomeMeshuggah
      @GiveMeSomeMeshuggah Год назад +15

      Or, on the flip side, you can use it to validate partial database records so that the don’t include sensitive columns and send them straight to an end user

    • @belkocik
      @belkocik Год назад

      @TomDoesTech would love to see that in your upcoming video :D

    • @rand0mtv660
      @rand0mtv660 Год назад

      @@GiveMeSomeMeshuggah wouldn't it make more sense to not query that data from the database in the first place? If you already know you cannot show it, why even query it? Or maybe I'm misunderstanding something.

    • @TomDoesTech
      @TomDoesTech Год назад

      @@GiveMeSomeMeshuggah that is brilliant!

  • @jeremykothe2847
    @jeremykothe2847 Год назад +206

    I love you, dude, but why the recent clickbait storm?

    • @ApexJnr
      @ApexJnr Год назад +40

      bills

    • @jaydeep-p
      @jaydeep-p Год назад +83

      Recent? Lol clickbait is the foundation of this channel

    • @tavin136
      @tavin136 Год назад +15

      Not so sure if it is really a clickbait, because zod validates values at runtime while giving you the type safety typescript provides, and the later can only enforce type safety at compile time. So he is right imo.

    • @TheJobCompany
      @TheJobCompany Год назад +2

      marketing

    • @jeremykothe2847
      @jeremykothe2847 Год назад +4

      @@tavin136 nothing in the title mentioned zod, nothing in the thumbnail hinted at it. It was "TS BAD!?" click to find out more. Theo loves TS, and the answer was "NO IT ISN"T", so it was the classic bait and switch. If anything you mentioned was hinted at, I'd have watched and enjoyed.

  • @RyanTipps
    @RyanTipps Год назад +1

    Colin explains on his blog why Yup's type inferences are wrong - biggest issue is that "the yup package treats all object properties as optional by default. Yet the inferred type indicates that all properties are required. 😕"

  • @BigluisVargas
    @BigluisVargas 7 месяцев назад

    The one for typescript is class-validator. By itself typescript does not validate the objects at runtime

  • @dixztube
    @dixztube Год назад

    Nobody, I mean nobody does the typescript better than me. I mean nobody.

  • @SeraphicRav
    @SeraphicRav Год назад +2

    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.

    • @Novagenesis
      @Novagenesis Год назад +1

      Sinclair keeps bugging people in reddit to swap to typebox, but he got really whiny at me and deleted a bunch of his comments when I tried to discuss it with him. That genuinely concerns me about the long-term life of the library because that kind of behavior has been a predictor of project-abandonment in the past. A lot of people have mentioned that typebox's download-count is artificially large because it is in a common `jest` dependency and jest stacks are downloaded automatically a LOT... so I don't know if I'd say typebox is anywhere near as stable/big as Zod yet. Of course, Zod is pretty small, too, compared to ajv.
      Flip-side, typebox has 22 contributors last I looked. Far fewer than zod, but "not 1 or 2". I think if the library felt less like OSS marketing hype and had trpc integration (or documented trpc integration), I would consider trying it out.

  • @tellyisko6908
    @tellyisko6908 Год назад +3

    Hey Theo can you make a video for a list of libraries that you always use most of the time in a project. I didn't know a lot of libraries until I got employed with an existing code base. I wish I knew how to use those when I was learning to get things better.

  • @ts8960
    @ts8960 Год назад

    zod doesnt stop at the first error for each field and its a waste of performance

  • @kirsanov2008
    @kirsanov2008 Год назад

    I am absolutely sure that zod deserves $ alias in todays JS world like it used to be for jQuery

  • @wesscat
    @wesscat Год назад +2

    If want to assert every type in a dynamically typed language, then it's better to learn static languages.

    • @NathanHedglin
      @NathanHedglin Год назад

      Exactly. JavaScript developers are terrible devs. 1,000 libraries just to fix JavaScript.

  • @mjerez6029
    @mjerez6029 Год назад +1

    Please check deepkit. Thats another whole new level!

  • @MrJester831
    @MrJester831 Год назад +4

    Real talk: this works even better in Rust

  • @ofmouseandman1316
    @ofmouseandman1316 Год назад +6

    I feel Zod is the exact opposite philosophy of Reflect MetaData: Make Code generate TypeSafety... wherhas Reflect metadata uses Types to be used as code.... after understing that I feel that ORMs such as TypeOrm who uses it only try to "hack" TS for a purpose that it is not made to, and moved to Prisma. But, after thinkering a bit with Zod I feel it could be the starting point of a nice ORM

  • @karixening
    @karixening Год назад +5

    if (typeof unknown !== 'object' || unknown === null || !('username' in unknown) || typeof unknown.username !== 'string' ....)
    is how you go from unknown to an object using type narrowing.

    • @DubiousNachos
      @DubiousNachos Год назад +1

      That "typeof unknown === null" would just be "unknown === null". The typeof operator always returns a string and doesn't have a null case.

    • @karixening
      @karixening Год назад

      @@DubiousNachos oh yeah, you're right. That was a typo.

    • @itskittyme
      @itskittyme Месяц назад

      if ( typeof unkown === "string") { yeah this is a username bruh }

  • @jamessunderland9284
    @jamessunderland9284 Год назад +3

    Fellow YC alum here. Gotta respectfully disagree with you. Runtime type checking is a recipe for disaster. I got my first post Mortem at Airbnb for someone thinking this was a good idea (visa vi an internal ruby gem). 500s do not benefit users! Data validation is a good idea, but is not the same thing as type checking. One of the biggest benefits of isomorphic typed systems is that in theory type validation becomes unnecessary at runtime (even for rpc and http calls). Confusing data validation and type safety is one of the biggest confusions I notice in junior and mid level engineers using typescript these days.

    • @t3dotgg
      @t3dotgg  Год назад

      I've seen devs confusing this maybe twice ever but i'll keep an eye out for it

    • @Novagenesis
      @Novagenesis Год назад +2

      This is a weird mirror-image take to my own.
      I hated on Typescript *because* people confused data validation with type safety. Type safety serves no purpose for your external interfaces or any interfaces that might go out of sync.
      Because of that, I used to prefer javascript with runtime type checking. That's sorta the "classic" way. You're not wrong that 500s don't benefit users, but it's still usually better than processing a bad request as if it were a good one. It's a balance, and something like Zod can be implemented to be as flexible as you can allow (only validating the pieces you need) if that is a real concern. But then, in my almost-20-years in the industry, I've never touched an API that was allowed to reach prod without some sort of runtime type checking.
      The reason I like zod as a Runtime type-checker is because of its compile-time inferences. Some of your "500" situations could actually get caught by the typescript compiler.

  • @ivokovacevic5221
    @ivokovacevic5221 Год назад +3

    Last time I checked, Zod had big performance issues. I hope they solved that. It might be worth giving Zod another chance

  • @GabrielMartinez-ez9ue
    @GabrielMartinez-ez9ue Год назад +4

    If you were to start TS again, how would you migrate a JS project to a TS? I am looking into migrating mine to TS and start learning on the go.

    • @offroaders123
      @offroaders123 Год назад +3

      I recently have been doing this with my projects, and I think I found a nice way to do it! I can make a demo example for you if this doesn't help explain it very well.
      First I add a tsconfig.json file to the root of my project. You can allow the TypeScript compiler to check your vanilla JavaScript files too, by setting both the `compilerOptions` properties `allowJS` and `checkJS` to true. This will start showing type errors for your code right in your editor, just like a full TypeScript file does.
      Then, you can go through each of your existing files, and add JSDoc type annotation comments, which are usable by the TypeScript compiler.
      Eventually, once you have all of your types specified using JSDoc, it is much easier to move the files over from `.js` to `.ts`, because your already took care of all the type errors. In your editor, it may give you an option to `infer types from JSDoc`, after your rename your files to `.ts`.
      This was a nice way for me to learn how to add type definitions before having to learn how the TypeScript syntax works, as the two are kind of separate steps in my mind.
      There may be some confusing parts to work out along the way, but this has seemed to work very well for my own codebases. Hopefully this helped at least a little bit!
      Here's some resources that I found to help me find this out:
      www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html
      www.mobiquity.com/insights/typescript-to-javascript-with-jsdoc-and-back

    • @GabrielMartinez-ez9ue
      @GabrielMartinez-ez9ue Год назад +2

      @@offroaders123 WOW... THANKS A LOT. You have been an incredible help. Wish more people would respond that detailed to messages! 😃😁

    • @offroaders123
      @offroaders123 Год назад

      @@GabrielMartinez-ez9ue So glad I could help! I was worried that was too long too, haha.

  • @ClaudioBrogliato
    @ClaudioBrogliato Год назад +3

    This is very interesting, if you couple it with a code generator tool that generates models starting from a self documented api (e.g. swagger) that'd make a nice stack.

  • @PhilipAlexanderHassialis
    @PhilipAlexanderHassialis Год назад +3

    Excellent video. Zod is a masterpiece in engineering. Also now that you mentioned react-hook-form, give some love to react-ts-form - you 'll like what you see, I am sure.
    P.S. isn't it about to get a clapperboard or somehow introduce the functionality through e.g. hand clapping? The audio isn't entirely synced, at least on my end :S

  • @NeilTheFisher
    @NeilTheFisher Год назад +3

    You can actually make typescript "run" if you use something like typia, which validates json against your typescript types.
    Getting it working with tRPC is a little tedious though since it's geared towards zod so much

  • @flemminghansen7748
    @flemminghansen7748 Месяц назад

    I really don't like Zod. I get the idea, but in my experience, it has been a pain. Sure it looks great when presented and used properly, but in the real world stupid shit happens, and you'll most likely end up with abstracted code that's really hard to understand. That's what happened in my project. And as for newcomers, it's a pain to go through a lot of documentation to do simple validations.

  • @rand0mtv660
    @rand0mtv660 Год назад +17

    What I like about these validators like Yup and Zod is the way schema is written. It's so easy to read and understand what the schema represents or expects. Also, creating a type from that schema is a super powerful thing. You can just infer type of that schema and use that with useForm() from react-hook-form. Working with forms has never been so nice until I started combining react-hook-form with one of these validator libraries. It also allows developers with less experience to build consistent form experiences.
    I personally use Yup just because in few instances of validating stuff in frontend forms it just had the ability to add better custom error messages and I could validate enums more easily. For example I get a user role enum type from backend and I loop over that enum to create options for a select dropdown, so that when a new user is created, you can pick a role to assign to it. Using Yup, I can easily validate that role selected is one of expected roles from that enum. Yup just handled these few scenarios in a nicer way and when I compared it to Zod. Zod just couldn't do some of these without too much ridiculous code or not even do something at all, but it's a library that I'll definitely re-evaluate frequently. Since I write frontend only, I really don't need Zod for more complex validations that I might do on backend.

    • @binaakene7942
      @binaakene7942 Год назад

      Was about to even ask what the difference between this and yup is. Seems exactly like what yup has been doing for a while but it’s getting so much hype

    • @Microphunktv-jb3kj
      @Microphunktv-jb3kj Год назад

      prisma+tRPC+zod is pretty nice combo :D

    • @jlf_
      @jlf_ Год назад

      yup without strict() is useless and actually was a problem for me. It actually accepts array of strings if you have a .string()

    • @butterfly7562
      @butterfly7562 Год назад

      I also use yup because zod produces some strange type errors

  • @zombizombi
    @zombizombi 11 месяцев назад

    Javascript/Typescript are madness. When you need a library to ensure type safety... so glad I left web dev. I sometimes wonder if the only people who use javascript/typescript learned them as their first languages and just don't know any different.

  • @bashbunni
    @bashbunni Год назад +5

    First, nerds

  • @elson_correia
    @elson_correia Год назад

    Crazy how people are shocked with TS now. Solutions like zod are just patches to things software engineers should already be checking but dont because they dont understand what TS is actually doing and trust it.
    TS is NOT a language, its a tool same level as a linter.
    You dont need zod. You need common sense and programming skills.

  • @jrgalyen
    @jrgalyen Год назад

    So with zod, we have to duplicate typescript. Tremendous stupid. What is way cooler? ajv

  • @nexxel
    @nexxel Год назад +3

    Parse, don't validate!

  • @vellysongsremix8463
    @vellysongsremix8463 Год назад +1

    We've come full circle! Need to bring a statically typed language for web haha

  • @bullettime2808
    @bullettime2808 Год назад

    zod is great but it's slow af
    edit: I mean it makes Typescript slow so stuff like intellisense take a long time to popup

  • @seannewell397
    @seannewell397 Год назад +8

    First 3 seconds = 1 like. Zod is always worth a like. A thousand likes.
    But your face, your hair, your presence theo - priceless.

  • @ExcellentSycamore
    @ExcellentSycamore Месяц назад

    Anderson Cynthia Gonzalez Anthony Lopez Mary

  • @ExcellentSycamore
    @ExcellentSycamore Месяц назад

    Smith Linda Wilson Richard Lewis Thomas

  • @the-old-channel
    @the-old-channel Год назад +8

    Hot take: superstruct is superior to Zod. You should seriously consider it when choosing a validation library. It is first class supported by tRPC, has awesome TS experience and more extensible design paradigm (composition instead of fluent). It also has a smaller bundle size than Zod and runs faster.

    • @kyleroach2581
      @kyleroach2581 Год назад

      Did you develop superstruct lol

    • @the-old-channel
      @the-old-channel Год назад

      @@kyleroach2581 I just think it’s very underrated

  • @tigidou3344
    @tigidou3344 Год назад

    Perso, I never found any utility from TS.

  • @dev__adi
    @dev__adi Год назад +1

    let me guess, it's about zod

  • @sitcomrave
    @sitcomrave Год назад

    Isn't `ajv` and `typia` is better players in this field ?

  • @KarlOlofsson
    @KarlOlofsson Год назад +1

    This is pretty commonplace if you do automated quality control. Strong typing, validation libraries and test tools for business logic go hand-in-hand 😋

  • @xReDxTuRtLeZx
    @xReDxTuRtLeZx Год назад +1

    interesting vid theo. does it matter how many libraries we use, as long as they are useful? my college professor told us to reinvent the wheel every time because "libraries are inefficient for what you need" but i feel like that makes no sense because libraries are meant to help...

    • @AkosLukacs42
      @AkosLukacs42 Год назад +1

      Your professor might have a bit of "not invented here" syndrome.
      On a more serious note: any library you use, and any code you write is a liability. You must use your judgement to decide between writing it yourself, or choosing a library.

  • @ExcellentSycamore
    @ExcellentSycamore Месяц назад

    Brown Steven Robinson Larry Lee Kenneth

  • @ocean3323
    @ocean3323 Год назад

    Sounds like serde in rust, but serde is actually better

  • @hrahman3123
    @hrahman3123 Год назад +1

    This oddly feels like yup. Haven’t dug into the differences but that’s my thought when I saw Zod for the first time

    • @Novagenesis
      @Novagenesis Год назад

      Zod has better type-inference than Yup last I looked. Otherwise, not a lot of differences. Both are great libraries. I LOVE Zod's type-inference, though.
      One thing I hated about Typescript was having to build types AND validators against my interfaces, and knowing that if they fell out of sync all hell could break loose. Zod solves that.

  • @aldrickdev
    @aldrickdev Год назад

    Reminds me of Pydantic for Python

  • @blue_name_warrior
    @blue_name_warrior 5 месяцев назад

    This turns out to be a copilot ad lol

  • @Alex-uf2ie
    @Alex-uf2ie Год назад +2

    5:07 demontized

  • @vidigitusmarketing862
    @vidigitusmarketing862 Год назад +1

    Zod is great!
    Why do I have the impression that Javascript it's all about typing now? Since Typescript came in, all the Javascript's biggest concerns is suddently typing. Anyway, I still think Typescript makes a lot of sence and packages like Zod and Trpc are also essencial for the industry.

    • @snehanshuphukon728
      @snehanshuphukon728 Год назад

      JavaScript is a powerful language. Typescript makes it safe and fun to use. So it being all about typing is a good thing in my opinion.

    • @ABC-ip6jq
      @ABC-ip6jq Год назад

      @@snehanshuphukon728 I think Typescript sometimes gives people a false feeling of safety. As many people I come across mistake typescript running on execution. Also, a wrongly assumed/typed variable or function return is way more prone to lead to errors than the Javascript equivalent where you take for granted that you have to handle every type or data structure.
      However, if you don't enforce types and are aware of when and where it acts, Typescript is great.

    • @shrin210
      @shrin210 Год назад

      ​@@snehanshuphukon728Is typescript really fun ? 🫤

  • @mcgruff0972
    @mcgruff0972 Год назад +1

    Are we just reinventing C#/Java classes at this point?

    • @doc8527
      @doc8527 Год назад

      nope, it's completely irrelevant to class, don't treat concept behind based on the syntax.
      it's more about static/dynamic and runtime/compile type checking inside or between application like frontend &backend.
      Though I felt the runtime check from zod or yup might have performance tradeoff. Just not sure how much it will cost.

  • @codeChuck
    @codeChuck 7 месяцев назад

    Tried to use zod in Express backend ~9m ago. Very useful! It helps to reliably deliver backend workloads to a react frontend (admin panel with product listings).

  • @alexandervashchuk7795
    @alexandervashchuk7795 6 месяцев назад

    thanks for the video!

  • @chaczyk113
    @chaczyk113 Год назад

    I don't know... Maybe for some backend object definitions Zod might be fine, but on Front for forms validation, Yup is way more better! Zod is really pain in the ass for validating complex forms, whre yup has some handy features.

  • @tornikebuchukuri4114
    @tornikebuchukuri4114 Год назад

    what's the point of typescript if you're using a 3rd party library for typechecking? I get ts doesn't typecheck on runtime, which zod does but it just does not make any sense, it's just more logical to use a normal language with types rather than do this kind of crap.

  • @danbizirean4196
    @danbizirean4196 Год назад

    Inference part iz amazing.

  • @riolly
    @riolly Год назад

    My stupid explanation would be.. (front end validation + backend validation) * simplicity = zod.

  • @Wielorybkek
    @Wielorybkek 9 месяцев назад

    great explanation!

  • @tentacle_sama3822
    @tentacle_sama3822 Год назад

    sounds a lot like Dart

  • @nomadshiba
    @nomadshiba Год назад

    zod isnt that great tbh

  • @iGaMeProDZ
    @iGaMeProDZ Год назад

    Hey, I have a question, is the T3 stack SEO friendly? also is it good for medium to big app?

  • @UwU-dx5hu
    @UwU-dx5hu 11 месяцев назад

    Where is kal el?

  • @chawkichalladia1812
    @chawkichalladia1812 Год назад

    I never used zod, but I used yup a long time ago. if my memory is not failing me, didn't yup do the same things?

  • @animanaut
    @animanaut Год назад

    there is a cocept called "make illegal states unrepresentable” comming from functional languages like fsharp/haskell/scala using the type system. not sure if that is applicable for ts/js, but i would like to hear your opinion on it.

  • @AtomicCodeX
    @AtomicCodeX Год назад

    I do agree that typescript can be over kill
    But 2 videos ago you said typescript is good without the types, and it's not why you should use it, and now this 😂😂
    Just admit you have an agenda with JS
    Ps I fully agree I never use typescript as typescript, I just use it in the background, and if a data type needs to be that type, I use their types in production with packages like this.
    Especially before adding it to a database...
    I thought it was common sense though

    • @DubiousNachos
      @DubiousNachos Год назад

      I think Theo's argument is that as a consumer of libraries and built-in APIs, you don't need the Typescript-specific syntax 90% of the time. The language server is just going to run for you in the background and catch the majority of issues with just type inference.
      And most of the time when you do need to add typing, it's to add definitions to "boundary types" that can't easily be inferred - function parameters, type parameters for things like maps/arrays, the return type of fetch.
      Compile-time type safety is the only thing you're shooting for - screwing around with the type layer and making all these convoluted types is fun, but isn't always needed to reach that goal.
      As usual, Theo is vocalizing his opinions in a really strong way that isn't really open to nuance. I think he's right that most developers can get away with TypeScript that mostly looks like JavaScript, but when you do need to make something really general-use that isn't available as a library, that knowledge of how to work with the type layer - how to treat it as a functional language in itself - is the only way to make things work without lying to the compiler.

  • @luctielen
    @luctielen Год назад

    Zod is amazing!
    But don't look at the source if you want to sleep at night 😅

  • @JB-fh1bb
    @JB-fh1bb Год назад

    I really need to see the results of running the code to understand it. The lack of it killed this vid for me.

  • @jii808
    @jii808 Год назад

    Are you mostly using zod for user input and in API routes to check incoming body data?

  • @EdJones99
    @EdJones99 Год назад

    Zod is great, I'm surprised to see so many negative comments here.

  • @kristijanvidovic8986
    @kristijanvidovic8986 Год назад

    Which VS Code theme is this, can somebody tell me please?

  • @Indigo00757
    @Indigo00757 Год назад

    5:07 😂

  • @davealma88
    @davealma88 Год назад

    Great video, it help me to know how zod works!!

  • @brokebull
    @brokebull Год назад

    Looks like yup with better npm trends as zod

  • @NathanHedglin
    @NathanHedglin Год назад

    Purescript. There problem solved

  • @osembit
    @osembit Год назад

    Added to my project now :) thanks!

  • @Disorrder
    @Disorrder Год назад

    It's not in scope of responsibility of TS to check string's length or validate as email. There is also class-validator doing same thing btw.
    Typed languages only validate types, not values!

    • @benscherer7256
      @benscherer7256 Год назад

      Ts also can’t validate incoming unknown data at runtime.
      Zod does both validation and creates the ts types

  • @cazterk
    @cazterk Год назад

    what's the differebce with, "Yup?"

  • @SimonCoulton
    @SimonCoulton Год назад

    Yup was a game changer. Zod is even better.

  • @lacherolachero9409
    @lacherolachero9409 Год назад

    You mentioned, it gives the ability to write a validator one time in one place to validate both frontend and backend, how would you implement it in a monolith contains backend with express and frontend built by (any), would you export validations to external npm package? or how would you structure the project

    • @VictorMainaKinuthia
      @VictorMainaKinuthia Год назад

      Since your app is a monolith, both the backend and the front end are in the same code base. I guess all you’d have to do is import the validator in both files, and let SSR do its thing. Could be wrong, though.

  • @kingt1tus
    @kingt1tus Год назад

    schemawax is my favorite of these kind of libraries

  • @AditSharda
    @AditSharda Год назад

    They should add this into TRPC without needing any extra line of code. Okay, maybe a flag to enable/disable it.

    • @TomDoesTech
      @TomDoesTech Год назад

      What do you mean? You can use Zod schemas with tRPC natively

  • @denislukashevich5486
    @denislukashevich5486 Год назад

    It'd be very nice to show exact flows of Yup before just throwing it to the bin :) Especially since there already was one video about Zod (general deserves it though)

    • @ivanpartida7467
      @ivanpartida7467 Год назад

      Read Colin's essay about the designing of Zod, there he mentions Yup's type inference is wrong.

  • @MarioLopez-eu8tj
    @MarioLopez-eu8tj Год назад

    Let's get that platinum youtube button.

  • @shivamjhaa
    @shivamjhaa Год назад

    Damn... your thumbnail game is on next level 🤟

  • @Kairos26
    @Kairos26 Год назад

    damn
    u makin me hyped to learn this

  • @Leto2ndAtreides
    @Leto2ndAtreides Год назад +2

    It's nice having someone share this information - because I hadn't bothered looking for these solutions when I built my own.
    Will be useful on future projects (or existing - depends on spare time)
    👍

  • @Vietnamkid1993
    @Vietnamkid1993 Год назад

    Great video, looking forward to add it to my tool belt

  • @Louisi9
    @Louisi9 Год назад

    I personally prefer Yup, not really for any other reason than being able to use it with Formik natively.

    • @shrin210
      @shrin210 Год назад

      You should probably start using react-hook-form first

  • @MysterKnajt
    @MysterKnajt Год назад

    Is there a need to use ZOD for graphql response and rest-api response?
    Personally i think there is no need for graphql, but for rest-api it's considerable, because the response could not be validated on BE side. WDYT?

    • @colinmcd94
      @colinmcd94 Год назад

      Nope graphQL frameworks will do all your runtime validation for you typically.

  • @Michael-Martell
    @Michael-Martell Год назад

    So, Zod is used in addition to a typescript setup, or does it replace the necessity of Typescript in a project?

    • @TheAppleFreak
      @TheAppleFreak Год назад

      It's used in addition to TypeScript.

  • @arturamorfati
    @arturamorfati Год назад

    nice shirt, theo

  • @seannewell397
    @seannewell397 Год назад

    Anyone else think SDKS / APIs/ other libs should ship with zod schemas to power their TS types? Too cumbersome?

    • @nazarshvets7501
      @nazarshvets7501 Год назад

      No. A lots of BE frameworks have their own specification to providing public api. U cannot force them to do your job. Also it might be not TS Backend at all
      U should generate validators from OpenAPI Spec/GQL via codegen, or just manualy create them

    • @TomDoesTech
      @TomDoesTech Год назад

      We do this for an internal SDK that publishes and consumes kafka messages. The schema is stored in the SDK and you can't publish a message for a specific topic if parsing throws.

  • @ricardomonge2769
    @ricardomonge2769 Год назад

    Thanks for this kind of content. Really useful!

  • @alexnovikov1609
    @alexnovikov1609 Год назад

    Thanks!

  • @luissolanodev
    @luissolanodev Год назад

    Great video! I'm curious on why you say we hopefully won't need zod for validating external APIs though

    • @tini_
      @tini_ Год назад +1

      I think it is meant to say, "hopefully you won't need to validate an external API" (regardless of with zod or somehow else) since a good API would not randomly change the schema returned and break your client. They should more likely version the API if necessary.

  • @yavko
    @yavko Год назад +3

    I wrote my own validator that just uses the built in classes in js, and works fine for me

    • @EdJones99
      @EdJones99 Год назад +4

      You should release it as an npm package

  • @BleedingDev
    @BleedingDev Год назад +2

    I am much bigger fan of fp-ts. Upcoming fp-ts/schema is even more breathtaking than Zod! What do you think of it? 😊

    • @SuperQuwertz
      @SuperQuwertz Год назад

      I want to understand fp-ts but the docs- Q_Q

  • @AndyQuinteroM
    @AndyQuinteroM Год назад +1

    Or..... use rust 🤓

    • @NathanHedglin
      @NathanHedglin Год назад

      Or at least Purescript which is 100% type safe and compiles to JS, Go and C++

  • @putsstrat
    @putsstrat Год назад

    well isnt yup doing the same thing !

    • @t3dotgg
      @t3dotgg  Год назад +4

      Watch like 45 more seconds and I directly mention this lmao

    • @putsstrat
      @putsstrat Год назад

      @@t3dotgg i did xd

    • @praneshkmr
      @praneshkmr Год назад

      I dont think we can do discriminated union with Yup

    • @TomDoesTech
      @TomDoesTech Год назад +3

      Yup doesn't play nicely with TypeScript. You can infer types with Zod really easily and accurately. So if you have a function where the params are validated with Zod, you can infer the type from the schema so you have type checking for the dev and runtime validation.

    • @putsstrat
      @putsstrat Год назад

      @@praneshkmr you can always make your own test utils to cover any variation of data type , schema , data consistency and/or dependencies using tests . That wasn't my point .

  • @berrodev
    @berrodev Год назад

    I made a video about ZOD and viewers doesn’t seem to like this library (according my channel) 🥲

    • @TomDoesTech
      @TomDoesTech Год назад

      I read the comments on your video and they are ummm, interesting. Great video btw