← All Exercises

Function Overload Signatures

basictypescript~15min

Background

Function overloads allow a single function to have multiple type signatures, improving type inference for callers.

Problem

Write an overloaded function that returns a string when given a string input and a number when given a number input, with proper overload signatures.

Input

A string or a number as input.

Output

A string (uppercased) for string input, or a number (doubled) for number input.

Sample tests

Sample 1

Input: "hi"
Expected: "HI"

Your solution

Learning objective

Learn function overload signatures for type-safe polymorphic functions.