Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

TypeScript · Type Alias

void

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.

How it works

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.

Syntax

type Callback = (...args: Parameters) => void;

Returns

For functions, void denotes that callers should not receive a usable return value.

Key points

  • Use void primarily to communicate that a function's return result is intentionally not consumed.
  • Functions without a returned expression commonly receive void as their inferred return type.
  • A function type writes void after the arrow, alongside parameter types, for example (a: string) => void.
  • A named alias such as type voidFunc = () => void can describe reusable side-effect callbacks.
  • Contextually typed void callbacks may compute and return a value, but callers cannot rely on that value.

Common mistakes

  • Do not treat void as an alias for undefined; they are distinct TypeScript types.
  • A function assigned to a void-returning callback type may return a value, but that value is ignored.
  • An explicitly annotated function declaration returning void cannot return a value.

Example: A void-returning callback

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.

When to use it

Side-effect callbacks

Event handlers and lifecycle hooks where only side effects matter.

Ignored callback results

Public APIs that invoke user functions but deliberately discard their results.

Named callback aliases

Reusable function contracts for operations such as logging, notification, or cleanup.

Interview questions

QWhat does the void type represent?

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.

QCan a function assigned to a void-returning callback return a value?

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.

QWhat is the difference between an explicit void function and a void callback?

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.

  • undefined
  • never
  • any
  • unknown
  • Function types
  • Type Compatibility

Source: Documentation - More on Functions. Checked 2026-10-15.