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
140
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
87
Prisma the ORM that node was waiting for
puppo
0
120
How to scale up your projects like a pro
puppo
0
140
Alive, Tipi Sopravvisuti
puppo
0
130
ReactDay 2022 - Unit testing
puppo
0
120
How to scale up your angular projects like a pro
puppo
0
200
Prisma in the Air
puppo
0
440
Can typescript definitions survive even at runtime?
puppo
0
130
Is it possible to build your UI components using only web components?
puppo
0
96
Other Decks in Programming
See All in Programming
「接続」—パフォーマンスチューニングの最後の一手 〜点と点を結ぶ、その一瞬のために〜
kentaroutakeda
3
1.7k
Rethinking API Platform Filters
vinceamstoutz
0
140
社内規程RAGの精度を73.3% → 100%に改善した話
oharu121
13
8.3k
ふつうのRubyist、ちいさなデバイス、大きな一年 / Ordinary Rubyists, Tiny Devices, Big Year
chobishiba
1
500
Feature Toggle は捨てやすく使おう
gennei
0
240
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
920
飯MCP
yusukebe
0
150
S3ストレージクラスの「見える」「ある」「使える」は全部違う ─ 体験から見た、仕様の深淵を覗く
ya_ma23
0
890
maplibre-gl-layers - 地図に移動体たくさん表示したい
kekyo
PRO
0
410
仕様漏れ実装漏れをなくすトレーサビリティAI基盤のご紹介
orgachem
PRO
7
3k
CSC307 Lecture 14
javiergs
PRO
0
480
Nostalgia Meets Technology: Super Mario with TypeScript
manfredsteyer
PRO
0
100
Featured
See All Featured
KATA
mclloyd
PRO
35
15k
Mind Mapping
helmedeiros
PRO
1
130
Are puppies a ranking factor?
jonoalderson
1
3.1k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
WENDY [Excerpt]
tessaabrams
9
37k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.5k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
220
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
500
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
430
Agile that works and the tools we love
rasmusluckow
331
21k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
64
54k
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]