Skip to main content
Tolk supports the types void and never, similar to TypeScript. Both represent the absence of a value, but in different ways.

A function that returns nothing is void

Both functions below return void:
When the return type of a function is not specified, it is inferred from the return statements. A return without a value means “void”. Explicitly specifying fun(...): void behaves identically:

Special fields with void type

If a structure field is void, it indicates that the field does not exist at all. This technique is used in combination with generics <T = void>, allowing structures to express optional fields.

A function that never returns is never

An always-throwing function is an example:
In a match expression, branches that never return are also of type never:

Implicit never in unreachable conditions

The never type occurs implicitly when a condition is impossible to satisfy. More precisely, it means that no value of such a type can exist; no possible data can produce such a value:
Another case arises when a non-nullable type is checked against null:
Encountering never in a compilation error typically indicates an issue in the preceding code.

Stack layout and serialization

Both mean “absence of a value” and occupy zero stack slots and zero bits. For example, a void function does not place any value onto the stack. For details, follow TVM representation and Serialization.