void, never, and Function Signatures
Understand void for no-return and never for unreachable code.
Welcome
Two special return types — void and never — represent functions that don't produce a useful value and functions that never complete normally.
void: No Meaningful Return
void is used when a function performs a side effect but doesn't return a value. It allows returning undefined but signals that the return value should not be used.
function logError(msg: string): void {
console.error(msg);
// implicit return undefined
}All lessons in this course
- Parameter and Return Type Annotations
- Optional and Default Parameters
- Rest Parameters and Spread with Types
- void, never, and Function Signatures