Function Overloading in TypeScript

From the TypeScript cheat sheet · Functions · verified Jul 2026

Function Overloading

Define multiple function signatures for different parameter types

typescript
// Function overloading
function create(name: string): string
function create(age: number): number
function create(value: string | number): string | number {
  if (typeof value === "string") {
    return `Name: ${value}`
  }
  return value * 2
}

// Method overloading in class
class Calculator {
  add(a: number, b: number): number
  add(a: string, b: string): string
  add(a: any, b: any): any {
    return a + b
  }
}
⚠️ Overload signatures must be compatible with implementation
💡 Order overloads from most specific to least specific
📌 Consider union types instead of overloads

More TypeScript tasks

Back to the full TypeScript cheat sheet