Skip to content
AgileLogics
4 min read

Functions with Types

Prerequisites: Type annotations

A function's parameters and return value can each be annotated — the most common and highest-value place to add explicit types, since they document a function's contract for every caller.

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

const multiply = (a: number, b: number): number => a * b;

If you omit the return type, TypeScript infers it from the return statements — but writing it explicitly on public/exported functions makes the contract clear at a glance and catches an accidental wrong return type immediately.