TSadvancedts-evergreen

Function overloads

Many faces, one body.

Overload signatures let one function advertise several distinct call shapes — different argument types mapping to different return types — backed by a single implementation signature that callers never see.

parse: return type follows the argument type

TSintro
Press Run to execute

The output {"n":42,"s":"42","doubled":84,"shouted":"42"} shows each call landed on the matching overload — parse('42') returned the number 42 and parse(42) returned the string "42" — so n * 2 and s.toUpperCase() both typecheck with no cast or guard.