Parameter and Return Type Annotations
Add types to function inputs and outputs.
Parameter and Return Type Annotations is a free TypeScript Academy lesson on CoddyKit — lesson 1 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, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Welcome
Parameter Types
function greet(name: string): string {
return 'Hello, ' + name;
}Return Type Annotations
function add(a: number, b: number): number {
return a + b;
}Inferring Return Types
function double(n: number) {
return n * 2; // TypeScript infers: number
}Arrow Functions
const multiply = (a: number, b: number): number => a * b;void Return Type
function logMessage(msg: string): void {
console.log(msg);
}Function Type Expressions
type MathFn = (a: number, b: number) => number;
const add: MathFn = (a, b) => a + b;Multiple Return Types with Union
function findUser(id: number): User | null {
return db.find(u => u.id === id) ?? null;
}never Return Type
function fail(msg: string): never {
throw new Error(msg);
}Typed Callback Parameters
function run(callback: (n: number) => void): void {
callback(42);
}
run(n => console.log(n)); // OKOverloaded Function Signatures
function pad(s: string, n: number): string;
function pad(s: string, c: string): string;
function pad(s: string, x: number | string): string {
return typeof x === 'number' ? s.padStart(x) : s + x;
}Quick Check
Recap
Frequently asked questions
Is the “Parameter and Return Type Annotations” lesson free?
Yes — the full text of “Parameter and Return Type Annotations” is free to read here on the web, and the TypeScript Academy course includes 4 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 “Parameter and Return Type Annotations”?
Add types to function inputs and outputs. 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 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Parameter and Return Type Annotations” 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