this parameter typing; void, never
Type the special this parameter, understand lexical this with arrows, and learn when to return void vs never.
this parameter typing; void, never is a free TypeScript Academy lesson on CoddyKit — lesson 2 of 3. 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, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Intro
Goal: Type the special this parameter, know how arrows capture this lexically, and choose between void (no value) and never (no return).
this parameter typing
Add a leading parameter named this to type the expected receiver. It is not a real argument and only applies to non-arrow functions.
function setTitle(this: { title: string }, t: string): void {
this.title = t;
}
const model = { title: "Old" };
setTitle.call(model, "New");
console.log(model.title);Arrows & lexical this
Arrow functions capture the this from the surrounding scope; they cannot declare a this parameter.
const counter = {
n: 0,
tick: function () {
setTimeout(() => {
// Arrow keeps outer this (counter)
this.n++;
console.log(this.n);
}, 0);
},
};
counter.tick();void return
void means the function doesn’t return a meaningful value. Callers should not use its result.
function logMsg(msg: string): void {
console.log(msg);
}
const r = logMsg("hello"); // r is void (ignored)
// Returning a value here would error when annotated as voidnever return
never indicates the function does not return (throws or infinite loop). It is useful for exhaustive checks and impossible code paths.
function fail(message: string): never {
throw new Error(message);
}
function loopForever(): never {
while (true) {}
}
// Calling either function never returnsBest practices
Tips:
- Use this parameter only on non-arrow functions that depend on a receiver.
- Prefer arrow callbacks to avoid losing this.
- Annotate void for side-effect functions; use never for throw/loop or exhaustive guards.
this parameter check
Quick check: Which statement about the “this” parameter is TRUE?
Recap
Recap: Type the receiver with a this parameter in non-arrow functions, rely on arrows for lexical this, and use void vs never appropriately.
Frequently asked questions
Is the “this parameter typing; void, never” lesson free?
Yes — the full text of “this parameter typing; void, never” is free to read here on the web, and the TypeScript Academy course includes 3 lessons in total. 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.
What will I learn in “this parameter typing; void, never”?
Type the special this parameter, understand lexical this with arrows, and learn when to return void vs never. 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; this is — lesson 2 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “this parameter typing; void, never” 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
- Function overloads & call signatures
- this parameter typing; void, never
- Assertion functions & user-defined type guards