Overloads allow one function to accept different input shapes and return different output types. You write multiple signatures, then a single implementation that handles both.
Parse a single string to a number, or an array of strings to an array of numbers. Use Number or parseFloat and keep the logic small.
function len(x: string): number;
function len(xs: string[]): number[];
function len(x: string | string[]) {
return Array.isArray(x) ? x.map((s) => s.length) : x.length;
}
Create an overloaded parseNumber that handles a string or an array of strings.