Function Overloading

Function overloading allows you to define multiple signatures for a function.

Snippet:

function greet(person: string): string; function greet(person: string, age: number): string; function greet(person: string, age?: number): string { return age ? `Hello ${person}, age ${age}` : `Hello ${person}`; }

Example:

function calculate(a: number, b: number): number; function calculate(a: string, b: string): string; function calculate(a: any, b: any): any { return a + b; }