void, never, and Function Signatures
Understand void for no-return and never for unreachable code.
void, never, and Function Signatures is a free TypeScript Academy lesson on CoddyKit. This is lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the TypeScript Academy learning path, and your progress syncs across the web and the CoddyKit app. The TypeScript Academy course includes 4 lessons in total.
Welcome
void: No Meaningful Return
function logError(msg: string): void {
console.error(msg);
// implicit return undefined
}Difference Between void and undefined
const fn: () => void = () => 42; // Allowed! Caller ignores return
const fn2: () => undefined = () => 42; // Errorvoid in Callbacks
function run(cb: () => void): void { cb(); }
run(() => 'hello'); // OK — return value ignorednever: The Unreachable Type
function fail(msg: string): never {
throw new Error(msg);
}
function loop(): never {
while (true) {}
}never in Exhaustiveness Checks
type Shape = 'circle' | 'square';
function area(s: Shape): number {
switch (s) {
case 'circle': return 3.14;
case 'square': return 1;
default:
const _: never = s; // Error if a new shape is added
return 0;
}
}never Is a Subtype of Everything
Function Type Signatures
type Handler = (event: MouseEvent) => void;
type Transform = (input: string) => string;Call Signatures in Interfaces
interface Formatter {
(value: string): string;
locale: string;
}Construct Signatures
interface Constructor {
new (name: string): Animal;
}Combining void and never in Error Handling
function orThrow(val: string | null): string {
if (val === null) fail('null!'); // never
return val; // TypeScript knows this is reachable
}Quick Check
Recap
Learn TypeScript with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 101
- Lessons
- 352
Frequently Asked Questions
Is the “void, never, and Function Signatures” lesson free?
Yes — the full text of “void, never, and Function Signatures” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the TypeScript Academy course, upgrade to CoddyKit PRO. The TypeScript Academy course includes 4 lessons in total.
What will I learn in “void, never, and Function Signatures”?
Understand void for no-return and never for unreachable code. You practise TypeScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start TypeScript Academy?
No prior experience is required. TypeScript Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 4 of 4.
How long does the “void, never, and Function Signatures” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this TypeScript Academy lesson?
Yes. Every TypeScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
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