Codington
0 of 6 problems solved0%

Functions: Call Signatures & Overloads

6 exercises

Functions are the heart of TypeScript programs. You can describe a function's shape with a call signature:

type MathOperation = (a: number, b: number) => number; const add: MathOperation = (a, b) => a + b;

Function overloads let one function name support different input shapes with different return types:

function parse(input: string): string[]; function parse(input: number): number[]; function parse(input: string | number) { // Implementation handles both cases }

You write multiple signatures (overloads), then one implementation that handles all cases. The compiler picks the right signature based on what you pass in.

In this category, you'll:

  • Write function type expressions (type Fn = (x: number) => string)
  • Use optional parameters (name?: string) and rest parameters (...args: number[])
  • Create overloaded functions that return the correct type based on inputs
  • Understand when to use overloads vs. union types

Best practice: Keep each branch simple and predictable. The focus is on readable types with small, safe implementations.

CodingtonCodington

© 2025 Codington. Built with TypeScript, TanStack Start and a lot of console.log().