Function Overloads
Question
What are function overloads in TypeScript?
Hint
Overloads provide different types for different argument combinations.
Explanation
Function overloads allow a single function to have multiple type signatures for different argument combinations. You declare overload signatures (without bodies) followed by a single implementation signature. Example: function makeDate(timestamp: number): Date; function makeDate(y: number, m: number, d: number): Date; function makeDate(yOrTs: number, m?: number, d?: number): Date { ... }. The implementation signature must be compatible with all overloads. Overloads are useful for functions that return different types based on arguments. The caller sees only the overload signatures, not the implementation.
Related Resources
Related Lessons
- Functions
Learn functions.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.