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
110
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
73
Prisma the ORM that node was waiting for
puppo
0
93
How to scale up your projects like a pro
puppo
0
120
Alive, Tipi Sopravvisuti
puppo
0
100
ReactDay 2022 - Unit testing
puppo
0
100
How to scale up your angular projects like a pro
puppo
0
150
Prisma in the Air
puppo
0
410
Can typescript definitions survive even at runtime?
puppo
0
110
Is it possible to build your UI components using only web components?
puppo
0
83
Other Decks in Programming
See All in Programming
Beyond Portability: Live Migration for Evolving WebAssembly Workloads
chikuwait
0
390
Cline指示通りに動かない? AI小説エージェントで学ぶ指示書の書き方と自動アップデートの仕組み
kamomeashizawa
1
580
XP, Testing and ninja testing
m_seki
3
210
DroidKnights 2025 - 다양한 스크롤 뷰에서의 영상 재생
gaeun5744
3
330
PostgreSQLのRow Level SecurityをPHPのORMで扱う Eloquent vs Doctrine #phpcon #track2
77web
2
390
イベントストーミング図からコードへの変換手順 / Procedure for Converting Event Storming Diagrams to Code
nrslib
1
500
iOSアプリ開発で 関数型プログラミングを実現する The Composable Architectureの紹介
yimajo
2
220
Goで作る、開発・CI環境
sin392
0
130
来たるべき 8.0 に備えて React 19 新機能と React Router 固有機能の取捨選択とすり合わせを考える
oukayuka
2
870
Kotlin エンジニアへ送る:Swift 案件に参加させられる日に備えて~似てるけど色々違う Swift の仕様 / from Kotlin to Swift
lovee
1
260
Java on Azure で LangGraph!
kohei3110
0
170
Team topologies and the microservice architecture: a synergistic relationship
cer
PRO
0
1.1k
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.3k
Agile that works and the tools we love
rasmusluckow
329
21k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Designing for humans not robots
tammielis
253
25k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
A Modern Web Designer's Workflow
chriscoyier
694
190k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
A designer walks into a library…
pauljervisheath
207
24k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
800
Side Projects
sachag
455
42k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
2.9k
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]