$30 off During Our Annual Pro Sale. View Details »
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
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
78
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
120
ReactDay 2022 - Unit testing
puppo
0
110
How to scale up your angular projects like a pro
puppo
0
180
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
89
Other Decks in Programming
See All in Programming
WebRTC、 綺麗に見るか滑らかに見るか
sublimer
1
160
テストやOSS開発に役立つSetup PHP Action
matsuo_atsushi
0
150
Rediscover the Console - SymfonyCon Amsterdam 2025
chalasr
2
160
[堅牢.py #1] テストを書かない研究者に送る、最初にテストを書く実験コード入門 / Let's start your ML project by writing tests
shunk031
12
7.1k
TUIライブラリつくってみた / i-just-make-TUI-library
kazto
1
350
AIコーディングエージェント(Manus)
kondai24
0
160
ソフトウェア設計の課題・原則・実践技法
masuda220
PRO
26
22k
これだけで丸わかり!LangChain v1.0 アップデートまとめ
os1ma
6
1.7k
tparseでgo testの出力を見やすくする
utgwkk
1
180
ViewファーストなRailsアプリ開発のたのしさ
sugiwe
0
430
How Software Deployment tools have changed in the past 20 years
geshan
0
28k
【CA.ai #3】ワークフローから見直すAIエージェント — 必要な場面と“選ばない”判断
satoaoaka
0
230
Featured
See All Featured
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
132
19k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.6k
Speed Design
sergeychernyshev
33
1.4k
Build The Right Thing And Hit Your Dates
maggiecrowley
38
3k
Navigating Team Friction
lara
191
16k
It's Worth the Effort
3n
187
29k
Making the Leap to Tech Lead
cromwellryan
135
9.7k
RailsConf 2023
tenderlove
30
1.3k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
15k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Practical Orchestrator
shlominoach
190
11k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.5k
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]