---
source: https://iinventedlight.com/library/notes/typescript-functions.md
title: "Typing functions in TypeScript"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC BY 4.0 (microsoft/TypeScript-Website); prose restates cited source lines"
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: TypeScript"
tags: typescript, functions, generics
sources:
  - id: S1
    title: "TypeScript: Documentation - More on Functions"
    publisher: TypeScript (Microsoft)
    url: https://www.typescriptlang.org/docs/handbook/2/functions.html
    accessed: 2026-11-04
    license: "CC BY 4.0 (microsoft/TypeScript-Website)"
  - id: S2
    title: "TypeScript: Documentation - Everyday Types"
    publisher: TypeScript (Microsoft)
    url: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
    accessed: 2026-11-04
    license: "CC BY 4.0 (microsoft/TypeScript-Website)"
---
# 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]

```ts
function first<T>(arr: T[]): T | undefined { return arr[0]; }
```

## Key points
- `(a: string) => void` means one string parameter named a and no return value. [S1]
- Return types are usually inferred, including for generic functions. [S1]

## Claims
- id: C1
  claim: The simplest way to describe a function is a function type expression.
  source: S1
  evidence: "The simplest way to describe a function is with a function type expression."
- id: C2
  claim: Generics describe a correspondence between two values.
  source: S1
  evidence: "generics are used when we want to describe a correspondence between two values"
- id: C3
  claim: Parameter type annotations go after the parameter name.
  source: S2
  evidence: "Parameter type annotations go after the parameter name:"
- id: C4
  claim: You can add return type annotations.
  source: S2
  evidence: "You can also add return type annotations."

## Sources
- [S1] TypeScript: Documentation - More on Functions. TypeScript (Microsoft). https://www.typescriptlang.org/docs/handbook/2/functions.html . License: CC BY 4.0 (microsoft/TypeScript-Website). Accessed 2026-11-04.
- [S2] TypeScript: Documentation - Everyday Types. TypeScript (Microsoft). https://www.typescriptlang.org/docs/handbook/2/everyday-types.html . License: CC BY 4.0 (microsoft/TypeScript-Website). Accessed 2026-11-04.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
