Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Keep alive your typescript definitions using Zod
Search
Luca Del Puppo
January 16, 2023
Programming
170
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
100
Prisma the ORM that node was waiting for
puppo
0
140
How to scale up your projects like a pro
puppo
0
160
Alive, Tipi Sopravvisuti
puppo
0
150
ReactDay 2022 - Unit testing
puppo
0
150
How to scale up your angular projects like a pro
puppo
0
220
Prisma in the Air
puppo
0
490
Can typescript definitions survive even at runtime?
puppo
0
170
Is it possible to build your UI components using only web components?
puppo
0
130
Other Decks in Programming
See All in Programming
Java 27新機能 / Java 27 new features
kishida
2
200
CodeRabbitの効果検証と過ごしてみた3ヶ月
armondando
0
140
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
190
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
250
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
1.1k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
450
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.5k
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
150
Turning Architecture into Unit Tests in the AI Era (NSSpain XIV)
steliosf
PRO
1
130
Domain-Driven Transformation
hschwentner
2
2.3k
Rでドレミ/Do-Re-Mi_with_R
florets1
0
120
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
120
Featured
See All Featured
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
730
Paper Plane
katiecoart
PRO
4
53k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
540
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
320
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
300
The Pragmatic Product Professional
lauravandoore
37
7.5k
Designing Experiences People Love
moore
143
24k
Automating Front-end Workflow
addyosmani
1369
210k
Balancing Empowerment & Direction
lara
6
1.3k
Accessibility Awareness
sabderemane
1
230
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
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]