TS EXPERTChapter 4 · TS Expert
Function Overloads
Overloads describe a function that returns different types for different arguments. Write several signatures without bodies, then one implementation whose signature covers them all. Callers only see the overload signatures, so every call gets an exact return type: parse("42") returns a number, and parse(["1", "2"]) returns number[].
Worked example
How it reads
- The first two lines are what callers see
- The implementation signature must accept every overload's arguments
oneis anumberandmanyis anumber[], no casts needed

Cloud tip: If a union parameter and a union return type would do, prefer that. Use overloads when the return type depends on the argument type.


