typeover
curriculum

Curriculum Errors Error union returns (!T) exercise 5 · fill-word

Error union returns (!T)

Fill the missing payload type for a function that fails-or- returns-nothing. Four letters, lowercase — Zig's name for the unit type.

TypeScript reference
Fill the blanks →

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.