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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Luca Del Puppo
January 16, 2023
Programming
160
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
99
Prisma the ORM that node was waiting for
puppo
0
140
How to scale up your projects like a pro
puppo
0
150
Alive, Tipi Sopravvisuti
puppo
0
150
ReactDay 2022 - Unit testing
puppo
0
140
How to scale up your angular projects like a pro
puppo
0
210
Prisma in the Air
puppo
0
480
Can typescript definitions survive even at runtime?
puppo
0
160
Is it possible to build your UI components using only web components?
puppo
0
120
Other Decks in Programming
See All in Programming
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
230
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
720
片田舎のおっさん、 Swift Buildのダイアモンド問題解決の不具合修正PRを出すが、解決方法がキャッシュをしないようにすることであり、ビルド時間が伸びると言われてマージされないので高速化もする/swiftbuild
yimajo
0
280
【デモ】Kiroで体験する仕様駆動開発|設計からコーディングまでAIと進める開発フロー
cmkudo
0
390
AIと壁打ちしながら進めるコスト管理
fufuhu
2
1.7k
実装をデザインガイドラインに追従させるための取り組み / 260731-dip-mosh-design-system
dachi023
0
7.8k
freee が目指す データ マネジメント戦略 AI-Ready 時代を支える 攻めのガバナンスとは
freee
PRO
0
490
Oxlintはいいぞ(続)
yug1224
1
450
Go を使い始めて 2 ヶ月の学び / My first two months with Go
contour_gara
0
380
Introducing Stack Pull Request in GitHub
kkamegawa
0
100
freeeにおけるEvalsの実践例の紹介
freee
PRO
0
150
in-process GraphQL のすすめ #ginzajs
izumin5210
4
1.5k
Featured
See All Featured
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
310
The World Runs on Bad Software
bkeepers
PRO
72
12k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
580
Claude Code のすすめ
schroneko
67
230k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.4k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
550
It's Worth the Effort
3n
188
29k
The Limits of Empathy - UXLibs8
cassininazir
1
610
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]