Side-effect callbacks
Event handlers and lifecycle hooks where only side effects matter.
TypeScript · Type Alias
void describes functions whose return value is not used. It is inferred for functions without a returned value and has special behavior when used as a callback return type.
void describes the return type of functions whose result is not available for use. In a function type, it also allows an implementation to return a value, but callers typed against that function type observe the result as void; a directly declared void function must not return a value.
type Callback = (...args: Parameters) => void;For functions, void denotes that callers should not receive a usable return value.
(a: string) => void.type voidFunc = () => void can describe reusable side-effect callbacks.void as an alias for undefined; they are distinct TypeScript types.type Callback = () => void;
const logDone: Callback = () => {
console.log("done");
};
logDone();A callback typed as returning void is invoked for its effects; callers cannot use its result as a value.
Event handlers and lifecycle hooks where only side effects matter.
Public APIs that invoke user functions but deliberately discard their results.
Reusable function contracts for operations such as logging, notification, or cleanup.
void represents the return value of a function that does not return a value. A function with no return statements, or no explicit return value, is inferred as returning void.
Follow-up: How does void differ from undefined? undefined is a distinct type; void is specifically used to describe function return behavior and is not interchangeable with it.
For a contextual callback type such as () => void, the implementation may return another value, but the value is ignored by the caller. This is useful when a callback's result is intentionally unused.
Follow-up: Why prefer void over any for such callbacks? It prevents callers from using the callback result without an explicit, checked return type.
A directly declared function whose return type is void must not return a value. This restriction differs from contextual typing, where a function assigned to a void-returning function type can return a value.
Follow-up: What happens if the callback result is assigned elsewhere? The assigned variable retains the type void, so the implementation's returned value remains unavailable through that type.
undefinedneveranyunknownFunction typesType Compatibility