Function Types in TypeScript
From the TypeScript cheat sheet · Functions · verified Jul 2026
Function Types
Type annotations for functions and their parameters
typescript
// Function declaration
function add(a: number, b: number): number {
return a + b
}
// Arrow function
const multiply = (a: number, b: number): number => a * b
// Function type
type MathFn = (a: number, b: number) => number
const subtract: MathFn = (a, b) => a - b
// Optional parameters
function greet(name: string, title?: string): string {
return title ? `${title} ${name}` : `Hello ${name}`
}
// Default parameters
function log(message: string, level: string = "info"): void {
console.log(`[${level}] ${message}`)
}💡 Use optional parameters instead of overloads when possible
📌 Arrow functions preserve lexical this
✅ Always type function parameters