4
Question
How should I model an API result so every error case is exhaustively handled?
My current response type uses several optional properties, so impossible states compile.
type Result<T> = {
data?: T;
error?: string;
validationErrors?: Record<string, string>;
};
I want the UI to require separate handling for success, validation failure, authentication failure, and an unexpected server error.