Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
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
チームをチームにするEM
hitode909
0
290
Why Kotlin? 電子カルテを Kotlin で開発する理由 / Why Kotlin? at Henry
agatan
2
6.9k
Tinkerbellから学ぶ、Podで DHCPをリッスンする手法
tomokon
0
120
connect-python: convenient protobuf RPC for Python
anuraaga
0
380
ソフトウェア設計の課題・原則・実践技法
masuda220
PRO
26
22k
TypeScript 5.9 で使えるようになった import defer でパフォーマンス最適化を実現する
bicstone
1
1.2k
Integrating WordPress and Symfony
alexandresalome
0
150
関数実行の裏側では何が起きているのか?
minop1205
1
680
これだけで丸わかり!LangChain v1.0 アップデートまとめ
os1ma
6
1.8k
Building AI Agents with TypeScript #TSKaigiHokuriku
izumin5210
6
1.3k
なあ兄弟、 余白の意味を考えてから UI実装してくれ!
ktcryomm
11
11k
20 years of Symfony, what's next?
fabpot
2
350
Featured
See All Featured
Stop Working from a Prison Cell
hatefulcrawdad
273
21k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.7k
Thoughts on Productivity
jonyablonski
73
5k
Leading Effective Engineering Teams in the AI Era
addyosmani
8
1.3k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.8k
Reflections from 52 weeks, 52 projects
jeffersonlam
355
21k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
132
19k
Side Projects
sachag
455
43k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.2k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.8k
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]