TypeScript Types
Function types — callable contracts
A function type describes the argument types and return type expected by a caller. Parameter names are documentation rather than part of the compatibility identity. Compatibility also depends on function parameter variance and the compiler configuration. A function type describes calls, not validation of arguments supplied by untyped JavaScript. Example output: "3". The example was designed for strict checking with an ES2022 target; type annotations do not add runtime validation.
Formal Syntax & Structure
typescript syntaxtypescript
type Convert = (input: string) => number;Working Example
Example Snippettypescript
type Convert = (input: string) => number;const length: Convert = text => text.length;console.log(length("abc"));