When to use Zod?

I'v seen the youtube hype for Zod now, but it still unclear to me when I should actually use Zod. Most of the examples I find online use Zod for something like API-data or user input data (like forms). But I use TS for so much more (well try to any way, still learning 😉). Should I just forget that TS exists and use Zod for everything I used to do in TS or should I use TS when not dealing with API-data or user input?
20 Replies
robotkutya
robotkutya2y ago
TS doesn't have runtime validation
Vimes
VimesOP2y ago
Yes I know this, but most of the time I don't really need that.
robotkutya
robotkutya2y ago
that's very true
Vimes
VimesOP2y ago
well maybe I do 🤷‍♀️
robotkutya
robotkutya2y ago
but it's one of those things, that it comes up often enough that integrating it into your app makes sense almost always and then if you can integrate that into react query, etc it makes for a really nice dx
Vimes
VimesOP2y ago
Yes, I am using a horrible CMS so I get most of my data from the CMS as pure HTML. here Zod can only help me see if I get a string in runtime.
robotkutya
robotkutya2y ago
and all the runtime validation comes "for free" so to speak
Vimes
VimesOP2y ago
so do you use zod for "everything"? or just some things
robotkutya
robotkutya2y ago
me? I use it basically always when I can
Vimes
VimesOP2y ago
I'll try to write the entire app with Zod then🤔
robotkutya
robotkutya2y ago
Theo had a good bit about this, I remember seeing it on youtube lemme dig it up for you
Vimes
VimesOP2y ago
I've probably seen it. but even he mostly used it for API data or user input. Seems more verbose for simple components that take a string or a few strings as inputs
robotkutya
robotkutya2y ago
here it is
robotkutya
robotkutya2y ago
Theo - ping․gg
YouTube
You Might Be Using Typescript Wrong...
I'm getting increasingly tired of the "but TS is so much woooooork" comments so I figured I'd do a rant. If you have friends or coworkers who are using Typescript incorrectly, please send this video to them :) Also please use Zod more it's very good https://github.com/colinhacks/zod Join the Discord: https://t3.gg/discord Follow me on Twitter...
robotkutya
robotkutya2y ago
? I think I'm missing something....
Vimes
VimesOP2y ago
Don't confuse me with someone who knows what they are talking about. To me it just seemed like I needed more stuff in my code with things that are one-liners to type in TS. More stuff = more stuff to maintain/read
Keef
Keef2y ago
If its data thats coming from the app just use typescript, if you are interacting with 3rd party (app,api,forms etc) use zod
robotkutya
robotkutya2y ago
So if you absolutely know your types, then sure, you don't need zod
Keef
Keef2y ago
So you still generally use typescript but zod is for being able to ensure this data is shaped like this which typescript wont give you
robotkutya
robotkutya2y ago
what Keef said
Want results from more Discord servers?
Add your server