Skip to content

Functions

Goal: Write typed functions with clear signatures.

Arrow functions and function declarations both accept parameter and return types.

Example

function add(a: number, b: number): number {
  return a + b
}

const double = (n: number): number => n * 2

export function greet(name: string): string {
  return "hi " + name
}

Open in playground

Key takeaways

  • Return types are checked at every return.
  • Exported functions form your module API.
  • Prefer explicit returns on public functions.

Next: Control flow

Documentation