tezvyn:

Runtime Response Validation with Schema Libraries

Source: zod.devadvanced

TypeScript types evaporate at runtime, so a fetch response typed as User[] can be null or malformed. Schema libraries like Zod give static types and runtime guards from one contract. The footgun is using as instead of parse, silently reintroducing crashes.

TypeScript types vanish at runtime, so a fetch typed as User[] can return null or malformed data without complaint. Schema libraries like Zod let you declare a shape once and get both a static type and a runtime validator. Apply this at every untrusted boundary: HTTP responses, webhook bodies, config files, and user uploads. The footgun is treating parse as a dev-only check and falling back to as in production, which silently resurrects the runtime crashes the schema was meant to prevent.

Read the original → zod.dev

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Runtime Response Validation with Schema Libraries · Tezvyn