Command Palette

Search for a command to run...

Hectal
Phase 16: Advanced TypeScript
TypeScript · Exercise 5 of 6 PreviousNext
Intermediate

Accept dogs without letting a function ruin them

describe reads a list of animals. Today it is declared with Animal[], which lets it push a Cat into a list that others see as Dog[].

Change the parameter type so a Dog[] and a readonly Dog[] are both accepted, but the function cannot push. Keep the printed result (animal).

What Check tests

  1. Your code has no type errors
  2. The program prints animal
  3. A readonly list is accepted
  4. The parameter can no longer be pushed to

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.