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
150
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Keep alive your typescript definitions using Zod
Luca Del Puppo
January 16, 2023
More Decks by Luca Del Puppo
See All by Luca Del Puppo
Aware dependencies using Nx Graph
puppo
0
93
Prisma the ORM that node was waiting for
puppo
0
130
How to scale up your projects like a pro
puppo
0
140
Alive, Tipi Sopravvisuti
puppo
0
140
ReactDay 2022 - Unit testing
puppo
0
120
How to scale up your angular projects like a pro
puppo
0
210
Prisma in the Air
puppo
0
460
Can typescript definitions survive even at runtime?
puppo
0
150
Is it possible to build your UI components using only web components?
puppo
0
110
Other Decks in Programming
See All in Programming
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6.2k
TypeScript+Orvalで実現する型安全かつ堅牢でスケーラブルなマルチチャネル通知基盤 / TSKaigi Night talks ~after conference~
d0riven
0
350
The NotImplementedError Problem in Ruby
koic
1
840
Performance Engineering for Everyone
elenatanasoiu
0
180
Oxcを導入して開発体験が向上した話
yug1224
4
320
スマートグラスで並列バイブコーディング
hyshu
0
160
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
200
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
710
Strategic Design in the Frontend: Moduliths & Micro Frontends @DDDEurope
manfredsteyer
PRO
0
110
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
21
6.7k
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
360
A2UI という光を覗いてみる
satohjohn
1
140
Featured
See All Featured
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.3k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
620
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
160
Skip the Path - Find Your Career Trail
mkilby
1
150
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2k
It's Worth the Effort
3n
188
29k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
Raft: Consensus for Rubyists
vanstee
141
7.5k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
220
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
RailsConf 2023
tenderlove
30
1.5k
Ethics towards AI in product and experience design
skipperchong
2
310
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]