On this page
void
Prev: `never` | Up: builtins | Next: `keyof`
Rel: builtins, Structural Typing & Narrowing
Ref: TypeScript Docs — void
Tags: #public #web #typescript #builtins #tier/core
Syntax & Overview
type Callback = () => void;
Indicates a function's return value is not used.
Notes & Pitfalls
- Callback return
() => voidallows returning a value (ignored by caller): That's why[1, 2].forEach(x => out.push(x))compiles cleanly even thoughpush()returnsnumber.
Example
function runTask(cb: () => void): void {
cb();
}
const items: number[] = [];
runTask(() => items.push(1)); // allowed: return value is ignored
Linked from
Related notes
- tuts/typescript/builtins/keyof Linked here; links to this page; shared tags: #builtins, #tier, #typescript, #web
- tuts/typescript/builtins/never Linked here; links to this page; shared tags: #builtins, #tier, #typescript, #web
- tuts/typescript/builtins Linked here; links to this page; shared tags: #builtins, #typescript, #web
- tuts/typescript/type_system/structural_typing_and_narrowing Linked here; shared tags: #typescript, #web
- tuts/typescript/builtins/any shared tags: #builtins, #tier, #typescript, #web
- tuts/typescript/builtins/as_const shared tags: #builtins, #tier, #typescript, #web
- tuts/typescript/builtins/asserts shared tags: #builtins, #tier, #typescript, #web
- tuts/typescript/builtins/enum shared tags: #builtins, #tier, #typescript, #web
- tuts/typescript/builtins/infer shared tags: #builtins, #tier, #typescript, #web
- tuts/typescript/builtins/is shared tags: #builtins, #tier, #typescript, #web