void The void Type
Last updated: 2026-10-22
void The void Type
void means "no meaningful return value". Use it for loggers and event callbacks to tell callers not to expect a result.
| Group | Basic Types |
|---|---|
| Kind | Type |
| Strict mode | Not required |
ℹ️ Info The editor transpiles TypeScript to JavaScript and runs it (no type checking); see each example's Output for type-check results.
📝 Syntax
function log(msg: string): void {
console.log(msg);
}
type Handler = (event: string) => void;
⚙️ Parameters
| () => void | void in a callback's return position: implementations may return values, callers ignore them |
|---|
Returns:void is itself the return type: annotated functions have no meaningful result; under strict, using their return value yields void.
▶ Example
Edit the code below and click Try it to see the transpiled result:
Output:
[event] click
[warn] low battery
(Runtime output after transpilation; writing return 5 inside logEvent is a compile error)
💡 Notes
ℹ️ Info void functions allow bare return; and return undefined, but not returning other values.
💡 Tip Typing event callbacks as (e: Event) => void is standard: implementations may return anything without breaking the contract.
⚠️ Note void differs from undefined: undefined is a real value type, void is an intent declaration — do not mix them.
🏷️ Related Basic Types
💡 Related cases
More cases coming soon.
📚 Related tutorials
❓ FAQ
Q void vs undefined as a return type?
A () => undefined requires explicitly returning undefined; () => void just states "no usable result" and is freer. Callbacks normally use void.
Q Can I assign a void function's result to a variable?
A Syntactically yes (the variable becomes void), but it is just undefined and pointless. Avoid it under strict.
Q What does Promise<void> mean?
A The promise fulfills without data — the async op only signals completion (e.g. a save). Data-fetching APIs should be Promise<T>.