SpinTheMic
Pro

Interview practice question

A function returns different types in different cases

Frontend Engineering · TypeScript · Beginner

A function sometimes returns a string and sometimes returns null. How should you type and use it?

What a strong answer covers

Your AI report card counts how many of these ideas you cover.

  • Return type string or null.
  • Callers must handle null.
  • Explicit return annotation.
  • Consider result objects for errors.
  • Overloads if input determines output.
Practise this topic

Start without signing up. Sign in free to get an AI report card on your answer.

See all topics