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
Luca Del Puppo
January 16, 2023
Programming
0
120
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
77
Prisma the ORM that node was waiting for
puppo
0
110
How to scale up your projects like a pro
puppo
0
130
Alive, Tipi Sopravvisuti
puppo
0
110
ReactDay 2022 - Unit testing
puppo
0
110
How to scale up your angular projects like a pro
puppo
0
170
Prisma in the Air
puppo
0
420
Can typescript definitions survive even at runtime?
puppo
0
120
Is it possible to build your UI components using only web components?
puppo
0
87
Other Decks in Programming
See All in Programming
Register is more than clipboard
satorunooshie
1
470
Kotlin 2.2が切り拓く: コンテキストパラメータで書く関数型DSLと新しい依存管理のかたち
knih
0
430
CSC509 Lecture 11
javiergs
PRO
0
310
自動テストを活かすためのテスト分析・テスト設計の進め方/JaSST25 Shikoku
goyoki
3
660
AI 時代だからこそ抑えたい「価値のある」PHP ユニットテストを書く技術 #phpconfuk / phpcon-fukuoka-2025
shogogg
1
440
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
490
詳細の決定を遅らせつつ実装を早くする
shimabox
1
1k
TVerのWeb内製化 - 開発スピードと品質を両立させるまでの道のり
techtver
PRO
1
800
なぜ強調表示できず ** が表示されるのか — Perlで始まったMarkdownの歴史と日本語文書における課題
kwahiro
12
5.8k
Amazon Bedrock Knowledge Bases Hands-on
konny0311
0
150
Java_プロセスのメモリ監視の落とし穴_NMT_で見抜けない_glibc_キャッシュ問題_.pdf
ntt_dsol_java
0
190
AIの弱点、やっぱりプログラミングは人間が(も)勉強しよう / YAPC AI and Programming
kishida
9
4.5k
Featured
See All Featured
Embracing the Ebb and Flow
colly
88
4.9k
Being A Developer After 40
akosma
91
590k
Music & Morning Musume
bryan
46
6.9k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.8k
Designing for Performance
lara
610
69k
jQuery: Nuts, Bolts and Bling
dougneiner
65
8k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
The Cult of Friendly URLs
andyhume
79
6.7k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Making the Leap to Tech Lead
cromwellryan
135
9.6k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
10
670
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
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]