TypeScript Syntax and Type Operators

Overload signatures — multiple call contracts

Overloads declare multiple supported call forms for one implementation. The implementation signature must be compatible with the overloads but is not itself an additional public call form. A union argument may fail if no overload accepts the union, even when each constituent is accepted separately. Prefer a union parameter for cases with the same return contract; overloads are useful for input-dependent results. Example output: "3 12". Tested in the strict TypeScript 5.8.3 / ES2022 baseline; the example is not a runtime type validator.

Formal Syntax & Structure

typescript syntaxtypescript
function parse(value: string): number;function parse(value: number): string;

Working Example

Example Snippettypescript
function convert(value: string): number;function convert(value: number): string;function convert(value: string | number): string | number {  return typeof value === "string" ? value.length : String(value);}const size: number = convert("abc");console.log(size, convert(12));
TypeScript Reference