← All notes

Typing functions in TypeScript

Short answer

Annotate parameters after their names and, optionally, the return type after the parameter list. A function type is written like an arrow function: (a: string) => void. Use generics when the output type depends on the input type. [S1][S2]

function first<T>(arr: T[]): T | undefined { return arr[0]; }

Key points

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: TypeScript (Microsoft), TypeScript: Documentation - More on Functions, CC BY 4.0 (microsoft/TypeScript-Website); TypeScript (Microsoft), TypeScript: Documentation - Everyday Types, CC BY 4.0 (microsoft/TypeScript-Website).

Cite this

Permanent ID: iil:note:y14ve047

iinventedlight. 2026. "Typing functions in TypeScript." iinventedlight Library, iil:note:y14ve047, version of 2026-11-04. https://iinventedlight.com/library/notes/typescript-functions/. License: CC-BY-4.0.

@misc{iil_note_y14ve047,
  author = {{iinventedlight}},
  title = {{Typing functions in TypeScript}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-04},
  url = {https://iinventedlight.com/library/notes/typescript-functions/},
  note = {Permanent ID iil:note:y14ve047. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/typescript-functions.md.