Guided Notes

Functions & Types

Typing parameters and return values, optional, default and rest parameters, function type aliases, callbacks, and overloads.

Parameters and return types

Slide 1 / 4

function vat(net: number, rate: number = 0.18): number { return net * rate; }

β€’ Parameters need types (TypeScript can't infer them in a declaration). β€’ Return types can be inferred, but annotating exported functions documents intent and catches accidental changes. β€’ Calling with the wrong number or type of arguments is an error.

← Union, Intersection & Literal Types