JS Built-ins
TypeScriptbeginner

Interface β€” Function Type

πŸ“– Usage Example
interface Transformer { (input: string): string }
const upper: Transformer = s => s.toUpperCase()
upper('hello')   // β†’ 'HELLO'

A call signature in an interface declares the shape of a function type with full TypeScript checking.

Function Types as Interface Members

Interfaces can describe function signatures. A Comparator<T> is a function (a: T, b: T) => number.

Challenge: Implement compareByAge matching the Comparator<Person> type.

compareByAge({ name: 'a', age: 30 }, { name: 'b', age: 25 })  // β†’ 5
πŸ’‘ Hints (1)
  • β€’ Array.sort uses negative/zero/positive to determine order.