DEV Community

Cover image for ZOD is Typescript for Runtime - Less code but more Reliable
DX Knight
DX Knight

Posted on

1

ZOD is Typescript for Runtime - Less code but more Reliable

Zod is a schema validator, it means you give your object to it and it checks that if it is exactly the same as the interface that you defined or not, and if it isn't, it gives you an error!

What does it mean? It means that you don't need to use if-elses anymore like before, e.g.

if(name=== null || name==="")
...
if(name.length>5 && name.length<10)
...
if(number && number !==0 || number >0 ...)
Enter fullscreen mode Exit fullscreen mode

It does all this by itself only with the following command:

z.safeParse(formdata);
Enter fullscreen mode Exit fullscreen mode

more examples:

IP check example

Introduction ~7min πŸ‘Œ

To get to know it better, watch this video from WebDevelopSimplified:

7min ZOD introduction

Learn it completely ~30 min 🀩✨

To learn it completely, and use it to save alot of time from yourself and also shipping reliable code watch this video

ZOD in 30 min


VSCode Pro for Frontend developers: πŸŽ–οΈ

ZPack

Top comments (0)

11 Tips That Make You a Better Typescript Programmer

typescript

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields

...

Read the whole post now!

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay