Command Palette

Search for a command to run...

Hectal
Phase 2: Functions
TypeScript · Exercise 5 of 6 PreviousNext
Intermediate

Overloads: Result Follows Input

measure returns the length of a string, or a number padded to three digits. As written, its result is number | string for every call, so the two typed variables below fail.

Add two overload signatures above the implementation: (value: string): number and (value: number): string. Other values (like true) must be rejected.

What Check tests

  1. Your code has no type errors
  2. The console prints 5 007
  3. measure(true) is rejected

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Console

Nothing printed yet.