Curriculum Errors Error union returns (!T) exercise 2 · mcq
Error union returns (!T)
When a function CAN fail but has no meaningful success value
(a validator, a writer, a "check this and return"), the
return type is !void — either nothing (success) or an
error. 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.