Design Patterns · Middle · Question 59 of 75
What is the Result (Either) pattern for error handling?
type Result<T, E> = { ok: true; value: T } | { ok: false; error: E };- ✓Correct answer: Returning success or failure as a value, so the type system forces callers to handle errors
- 2Throwing errors with a result code
- 3Logging all results
Explanation
Expected failures (validation, "not found") become explicit. Truly unexpected bugs can still throw.