Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Keep alive your typescript definitions using Zod

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

Keep alive your typescript definitions using Zod

Luca Del Puppo

January 16, 2023

Transcript

25 slides
  1. Who I am Luca Del Puppo 
 (aka Puppo) 


    Full-Stack Developer @ Flowing a Claranet Company 
 and Microsoft MVP @puppo92 
 https://www.linkedin.com/in/lucadelpuppo/ 
 [email protected]
  2. ➔ Typescript enables type check but on BUILT - TIME

    ➔ After the build all your types disappears ➔ After the build all your considerations about types dissolve Why?
  3. import { z } from ‘zod’; const CustomerSchema = z.object({

    id: z.number(), name: z.string(), email: z.string(), phone: z.string(), }); Schema
  4. ➔ Parse throws an Error ➔ ZodError is the right

    error to check ➔ ZodError contains all the issues that describe the errors Something wrong?
  5. Create a layer between your app and the outside V

    a l i d a t i o n HTTP socket.io
  6. ➔ Typescript is awesome, but it’s good only on built

    time ➔ Create a validation layer between your app and the outside • Prevent execution of code with wrong data • You can get notifications if something is changed ➔ Using Zod, you can guarantee your types, both built-time and run-time Conclusion

More Decks by Luca Del Puppo

Other Decks in Programming