You type parameters and the return value, and TypeScript supports optional, default, and rest parameters.
ts
(): { a + b; }
(): {
title ? : name;
}
(): { n + by; }
(): {
nums.( a + n, );
}
You type parameters and the return value, and TypeScript supports optional, default, and rest parameters.
(): { a + b; }
(): {
title ? : name;
}
(): { n + by; }
(): {
nums.( a + n, );
}
You can describe a function's signature as a type — useful for callbacks and variables holding functions:
type BinaryOp = (a: number, b: number) => number;
const multiply: BinaryOp = (a, b) => a * b; // params inferred from BinaryOp
// callback parameter
function apply(op: (x: number) => number, val: number) { return op(val); }
function parse(x: string): number;
function parse(x: number): string;
function parse(x: any): any { return typeof x === "string" ? +x : String(x); }
Typing functions precisely is the core of TypeScript's value — callers get checked arguments and known return types, optional/default params model real-world flexibility, and function type aliases make higher-order code (callbacks, event handlers, middleware) self-documenting and safe.