Command Palette

Search for a command to run...

Hectal
Phase 5: Arrays, Tuples, Enums and Special Types
TypeScript · Exercise 2 of 6 PreviousNext
Beginner

Return a Pair, Typed

minMax returns the smallest and largest number. Its result is inferred as number[], so the caller's lo and hi might be undefined as far as TypeScript knows.

Give minMax a return type that is a tuple of exactly two numbers (labelled min and max). Then lo + hi type-checks, and reading a third element is an error.

What Check tests

  1. Your code has no type errors
  2. lo and hi are plain numbers
  3. Reading a third element is rejected
  4. The console prints 1 3

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.