Intermediate
Review: Make Every Case Count
The Shape type has three kinds. area ends with assertNever(shape), so the compiler reports that one kind is missing a case. Add the missing case to area.
Then write perimeter(shape: Shape): number, also with an exhaustive switch that ends in assertNever(shape). A circle's perimeter is 2 * Math.PI * radius, a square's 4 * side, a rectangle's 2 * (width + height).
The program logs area and perimeter of a few shapes. Do not remove assertNever.
What Check tests
- Your code has no type errors
- The rectangle area is 12
- The rectangle perimeter is 14
- The square perimeter is 20
- Both functions end in assertNever
- An unknown shape 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.
Press Run to see the page.
Console
Nothing printed yet.