Rest Parameters and Spread with Types
Type rest parameters and spread operations.
Rest Parameters and Spread with Types is a free TypeScript Academy lesson on CoddyKit — lesson 3 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
Typing Rest Parameters
function sum(...nums: number[]): number {
return nums.reduce((a, b) => a + b, 0);
}
console.log(sum(1, 2, 3, 4)); // 10Rest After Required Parameters
function log(level: string, ...messages: string[]): void {
console.log(level, messages.join(' '));
}
log('INFO', 'Server', 'started', 'on', 'port', '3000');Spreading Arrays into Functions
function add(a: number, b: number): number { return a + b; }
const args: [number, number] = [1, 2];
add(...args); // OK — tuple spread is type-safeSpreading with Regular Arrays
const nums = [1, 2]; // number[] — length unknown
// add(...nums); // Error: spread must match parameters
const pair: [number, number] = [1, 2];
add(...pair); // OK — tuple has known lengthRest Parameters vs arguments Object
Spreading Objects (Not Rest Params)
const a = { x: 1, y: 2 };
const b = { z: 3 };
const c = { ...a, ...b }; // { x: number; y: number; z: number }Overriding Properties with Spread
const base = { color: 'red', size: 5 };
const updated = { ...base, color: 'blue' };
// { color: 'blue', size: 5 }Typed Spread in Arrays
const a: number[] = [1, 2];
const b: number[] = [3, 4];
const c: number[] = [...a, ...b]; // [1, 2, 3, 4]Variadic Tuple Rest
type Strings = string[];
type StringsAndNumber = [...Strings, number];
const t: StringsAndNumber = ['a', 'b', 42];Rest in Destructuring
const [first, ...rest]: number[] = [1, 2, 3, 4];
// first: number, rest: number[]Quick Check
Recap
Frequently asked questions
Is the “Rest Parameters and Spread with Types” lesson free?
Yes — the full text of “Rest Parameters and Spread with Types” 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 “Rest Parameters and Spread with Types”?
Type rest parameters and spread operations. 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 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Rest Parameters and Spread with Types” 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