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
85
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
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
95
Other Decks in Programming
See All in Programming
モジュラモノリスにおける境界をGoのinternalパッケージで守る
magavel
0
3.5k
株式会社 Sun terras カンパニーデック
sunterras
0
2.1k
encoding/json/v2のUnmarshalはこう変わった:内部実装で見る設計改善
kurakura0916
0
400
Railsの気持ちを考えながらコントローラとビューを整頓する/tidying-rails-controllers-and-views-as-rails-think
moro
5
390
Docコメントで始める簡単ガードレール
keisukeikeda
1
110
AHC061解説
shun_pi
0
360
AI時代のシステム設計:ドメインモデルで変更しやすさを守る設計戦略
masuda220
PRO
5
870
エージェント開発初心者の僕がエージェントを作った話と今後やりたいこと
thasu0123
0
240
Goの型安全性で実現する複数プロダクトの権限管理
ishikawa_pro
1
200
どんと来い、データベース信頼性エンジニアリング / Introduction to DBRE
nnaka2992
1
270
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
540
エラーログのマスキングの仕組みづくりに役立ったASTの話
kumoichi
0
180
Featured
See All Featured
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
210
Practical Orchestrator
shlominoach
191
11k
GraphQLの誤解/rethinking-graphql
sonatard
75
11k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
300
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
1.9k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
78
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
290
Ruling the World: When Life Gets Gamed
codingconduct
0
170
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.6k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.1k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
110k
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]