Why `{ data, loading, error }` Lies — And Algebraic Data Types Fix Your Vibe Coding
An AI agent wrote a React hook, it returned { data, loading, error } . The render branch said if (loading) return < Spinner /> ; if (error) return < Err /> ; return < List data = {data} /> ; In production, data arrived, loading stayed true for a tick, and the list crashed on data.items.map . The type said Order[] | null . The state said "loaded". Both agreed. Neither was right. With functional programming, we can use Algebraic Data Types (ADTs) to cover the surfaces where vibe coding drops cases: async calls, error handling, and remote data. The Problem The { data, loading, error } shape is a habit, not a type. It describes one concept — "what does this request know right now?" — with three fields that can all have value, all be null/false/undefined , or any combination in between. Eight combinations but only four of them are legal. The compiler cannot tell one from the othe...