Command Palette

Search for a command to run...

Hectal
Phase 15: TypeScript in Real Projects
TypeScript · Exercise 1 of 6Next
Beginner

Read a port from the environment

Environment variables are text or missing. Write readPort(env: Env): number that reads env["PORT"], throws an Error if it is missing, throws if it is not a whole number, and otherwise returns the number.

The type Env and an env object are given. The program must print port: 3000.

What Check tests

  1. Your code has no type errors
  2. The program prints port: 3000
  3. readPort returns a number
  4. The result is a number, not a string

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.