typeover
curriculum

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

Error union returns (!T)

Fill the missing single character that marks a function's return type as an error union. Same character TypeScript uses to assert "definitely not null" — but in Zig it precedes the type, not follows it.

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.