TypeScript · Types that pay for themselves

How do function overloads work?

Mediumoverloadsfunctionsapi-designUpdated Oct 2026
Quiz this track

Short answer

Overload signatures describe several valid call shapes for one implementation. The implementation signature is not callable from outside, so each public overload must be declared explicitly.

An overloaded function has one or more signature declarations followed by a single implementation. Callers only see the signatures, not the implementation signature. That lets you describe precise input and output relationships while keeping one runtime function.

ts
function format(value: string): string;
function format(value: number): string;
function format(value: string | number): string {
  return typeof value === "number"
    ? value.toFixed(2)
    : value.trim();
}

format("  hello  ");
format(3.14159);

Rules to remember

  • The implementation signature must be compatible with every overload
  • The implementation signature is not visible to callers
  • Order matters: more specific overloads should come first
  • The implementation can be broader than any single overload
  • Overloads cannot be expressed with a single arrow function declaration

Overloads are useful when the return type depends on the argument type or when a function accepts a few distinct call shapes. For a simple union that always returns the same type, a single signature is easier to read and maintain.

If the implementation accepts a union that is wider than the overloads, callers still cannot use the wider form. That is intentional: the overloads are the public contract.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Is the implementation signature callable from outside?
  2. 2Why does overload order matter?
  3. 3Can an overload be implemented with an arrow function?
  4. 4When should you use an overload instead of a union?

Say it in the interview

Function overloads describe several valid call signatures and then provide one implementation. The implementation signature is not part of the public API, so every supported call shape needs its own overload. I use overloads when the return type depends on the arguments. I keep the implementation broad enough to satisfy all the overloads and put the most specific signatures first.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live TypeScript mock interview and get scored feedback on depth, clarity and confidence.