For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /packs/languages/typescript/functions.md.
Quick start

Functions

Give each named operation a declaration and a contract that explains what it consumes and produces.

Declaration and contract

Why

Selection, hashing, and project writes are different jobs. Keeping them separate makes workflows readable without making a caller memorize several positional strings.

Rules

  • MUST declare named helpers, handlers, factories, components, and exported operations with function. [review]
  • MAY express inline or returned callbacks with arrows. [review]
  • MAY assign a composition result to a const binding. [review]
  • MUST annotate the return contract of every exported function. [review]
  • MUST replace two or more authored parameters with one destructured object parameter. [review]
  • MUST give that object's named type a Params or Options suffix. [review]
  • MAY use the callback signature required by an external framework. [review]
  • MUST separate distinct jobs into functions and let the caller coordinate them. [review]

Example

type BuildEntryLinkParams = {
  readonly directory: string
  readonly entry: string
}

function buildEntryLink({ directory, entry }: BuildEntryLinkParams): string {
  return `${directory}/${entry}`
}

Focused examples leave out JSDoc unless they demonstrate it. The JSDoc contract still applies to authored source.

[review]

Typechecks establish signature use. Review checks declaration style, named inputs, and single responsibility unless a consumer configures additional lint rules.

Enforcement

Typechecks establish signature use. Review checks declaration style, named inputs, and single responsibility unless a consumer configures additional lint rules.