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 };

Explanation

Expected failures (validation, "not found") become explicit. Truly unexpected bugs can still throw.

Further reading

Problem with a question

Design Patterns · Middle · question 59

Test yourself

Take the Design Patterns · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz