Typing Variables As Functions
A function type describes a callable's signature
You can name the shape of a function — its parameters and return type — with a type alias, then reuse it for any variable that holds a function.
type MathOperation = (a: number, b: number) => number;
const add: MathOperation = (a, b) => a + b;
const subtract: MathOperation = (a, b) => a - b;
Notice add and subtract don't re-annotate a and b — because MathOperation already declares them, TypeScript infers the parameter types automatically. That's contextual typing.
Why this is useful — functions as arguments
A function type lets you accept a function as a parameter with full type safety:
type MathOperation = (a: number, b: number) => number;
function runOperation(a: number, b: number, operation: MathOperation) {
return operation(a, b);
}
runOperation(10, 5, add); // → 15
runOperation(10, 5, subtract); // → 5
The syntax to remember
A function type is (params) => returnType — the same arrow shape as an arrow function, but it describes a type, not a value.
type Predicate = (value: string) => boolean;
type Formatter = (n: number) => string;
type NoArgs = () => void;
Naming a function's signature turns "a function" into a contract. Callbacks, higher-order functions, and event handlers all become type-checked once you describe their shape.