Skip to content
All articles
DevelopmentSample

Strict TypeScript Habits That Survived Contact With Real Code

Narrowing over casting, discriminated unions over flag soup, and treating every API response as untrusted.

5 min readTypeScript · Next.js · Forms

Validate at the boundary

Data from forms, APIs, and query strings is untrusted until proven otherwise. A Zod schema at the boundary turns runtime surprises into compile-time-shaped errors.

This portfolio's contact form follows that pattern: React Hook Form for UX, Zod for truth.

Model states, not flags

Idle, loading, success, error — one discriminated union instead of four booleans that can combine into impossible states. Fewer states to test, fewer states to break.