Command Palette

Search for a command to run...

Hectal
Phase 2: Functions
TypeScript · Exercise 6 of 6 Previous
Intermediate

Build a Callable Logger

A logger is a function you call with a message, and it also has a count of the messages so far and a reset() method. Describe it with a type named Logger: a call signature taking a string and returning nothing, plus count: number and reset(): void.

The code below already builds it; only the type is missing. Calls with a number, and assigning text to count, must be rejected.

What Check tests

  1. Your code has no type errors
  2. The console prints both log lines, then 2 and 0
  3. info(42) is rejected
  4. Assigning text to count is rejected
  5. new is not allowed on a logger

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.