Curriculum Errors Error union returns (!T) exercise 3 · mcq
Error union returns (!T)
When you DO want to pin down which errors a function can return — for documentation, for API stability, for narrower catch handlers — name the error set BEFORE the bang. Pick the right signature.
TypeScript reference
About this theme
A function that can fail declares a return type with a leading bang: !T means "either a T or an error." The error set is usually INFERRED from the function body — every return error.X line is added to the implicit set. !void is the common shape for functions that succeed silently or fail (validators, writers). The caller consumes via try, catch <default>, or catch |err| handler. The bang plus a body that mentions error.X is the whole error story.