Dev Helpers

TypeScript / Function signatures

Invoke an optional argument callback

Dev Helpers · May 4, 2026

An optional callback parameter is part of the callable contract. A caller may omit it, so the implementation must handle that case.

Worked example

type Task = (name: string, attempt?: number) => string;
const task: Task = (name, attempt = 1) => name + " #" + attempt;
console.log(task("ship"));

Result

ship #1

Implementation notes

Optionality in a callback signature specifies what the caller may omit. Marking every parameter optional can unnecessarily burden callback implementations.

Try it yourself

Invoke the same function with an argument, without it and with a falsy value.

Open the TypeScript example →

Editorial date May 4, 2026 · Published December 6, 2026

Related articles

Reject fractional cent amounts

A numeric type cannot by itself guarantee whole cents. Validate integrality where money enters the typed part of the application.

Infer route names from a registry

A route registry can drive both lookup and allowed route names. Type the keys from the registry so a removed route cannot survive in a separate union.