Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

Part 4.1Functions in TypeScript

Function types make a program's inputs and outputs explicit. TypeScript can infer many return types, but annotations are useful at public boundaries.

Parameters

TypeScript
function formatPrice(price: number, currency = "GBP"): string {
  return `${currency} ${price.toFixed(2)}`;
}

Return types

An optional parameter follows required parameters. A function that does not return a useful value has return type void. Do not annotate everything automatically; use annotations where they communicate an important contract.

Feedback 👍
Comments are sent via email to me.