Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Keep alive your typescript definitions using Zod
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Luca Del Puppo
January 16, 2023
Programming
0
130
Keep alive your typescript definitions using Zod
Luca Del Puppo
January 16, 2023
Tweet
Share
More Decks by Luca Del Puppo
See All by Luca Del Puppo
Aware dependencies using Nx Graph
puppo
0
83
Prisma the ORM that node was waiting for
puppo
0
120
How to scale up your projects like a pro
puppo
0
130
Alive, Tipi Sopravvisuti
puppo
0
120
ReactDay 2022 - Unit testing
puppo
0
120
How to scale up your angular projects like a pro
puppo
0
190
Prisma in the Air
puppo
0
430
Can typescript definitions survive even at runtime?
puppo
0
130
Is it possible to build your UI components using only web components?
puppo
0
92
Other Decks in Programming
See All in Programming
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
200
AIと一緒にレガシーに向き合ってみた
nyafunta9858
0
240
コントリビューターによるDenoのすゝめ / Deno Recommendations by a Contributor
petamoriken
0
200
AI & Enginnering
codelynx
0
110
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
1.2k
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
610
疑似コードによるプロンプト記述、どのくらい正確に実行される?
kokuyouwind
0
390
CSC307 Lecture 02
javiergs
PRO
1
780
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
7.4k
AIによるイベントストーミング図からのコード生成 / AI-powered code generation from Event Storming diagrams
nrslib
2
1.9k
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
1
980
Fragmented Architectures
denyspoltorak
0
160
Featured
See All Featured
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
66
37k
HDC tutorial
michielstock
1
380
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
The SEO identity crisis: Don't let AI make you average
varn
0
290
Building a Scalable Design System with Sketch
lauravandoore
463
34k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Discover your Explorer Soul
emna__ayadi
2
1.1k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
450
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
140
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
66
Transcript
Keep alive your typescript definitions using Zod Luca Del Puppo
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]
Typescript journey 1
10 years ago
The developers reaction
interface CustomerModel { id: number; name: string; email: string; phone:
string; } Interfaces
type CustomerModel = { id: number; name: string; email: string;
phone: string; }; Types
HTTP Request
But after a while…
➔ 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?
Prevent ugly mistakes 2
Zod is your super hero
import { z } from ‘zod’; const CustomerSchema = z.object({
id: z.number(), name: z.string(), email: z.string(), phone: z.string(), }); Schema
import { TypeOf } from ‘zod'; type CustomerModel = TypeOf<typeof
CustomerSchema>; Convert to type
const res = CustomerSchema.parse({ id: 1, name: 'John Doe', email:
'
[email protected]
', phone: '555-555-5555' }); Parse method
➔ Parse throws an Error ➔ ZodError is the right
error to check ➔ ZodError contains all the issues that describe the errors Something wrong?
Do you hate exceptions? use safeParse
safeParse Success ➔ success: true ➔ data: Output Error ➔
success: false ➔ error: ZodError
Benefits of using Zod
Create a layer between your app and the outside V
a l i d a t i o n HTTP socket.io
Demo 3
Conclusion 4
➔ 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
CODE SLIDE
Thanks! That’s All! Luca Del Puppo @puppo92 https://www.linkedin.com/in/lucadelpuppo/
[email protected]