Function Type (TypeScript)
A function type describes the parameters a function takes and the value it returns, written like `(a: number) => string`. It lets you type variables, parameters, and callbacks that hold functions.
TypeScript
In plain JavaScript a callback could be anything; a function type pins down its signature so the compiler checks that you call it correctly and pass the right kind of function.
Annotating parameter and return types also gives you inference inside callbacks — TypeScript knows what type each argument is without you repeating the annotation.
Syntax
type Fn = (param: type) => returnType;Examples
TypeScript
type Transform = (input: string) => number;
const length: Transform = (s) => s.length;
console.log(length("hello"));Output:
5