What is a function overload in TypeScript?

Answer

Function overloads allow you to define multiple call signatures for a single function, letting it accept different argument types and return different types based on what is passed. You declare the overload signatures first (without body), then implement with a single implementation signature (with body): function format(value: string): string; function format(value: number): string; function format(value: string | number): string { return String(value); }. TypeScript uses the overload signatures for type checking (not the implementation signature) — callers see only the declared overloads. Overloads are resolved in order — TypeScript picks the first matching signature. The implementation signature must be compatible with all overload signatures. Use overloads when a function's return type or behavior genuinely depends on the argument types. For simpler cases, union types and optional parameters are cleaner. Overloads also work on class methods and interface methods.