Handle Every Case of a Union
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Shapes are a union told apart by kind: a circle with a radius, a square with a size, or a rectangle with a width and height. Export the Shape type and area(shape). Also export assertNever(value: never), which throws, and call it when no case matched, so adding a new shape without handling it becomes a type error.
Your code must pass
- Works out each shape's area
- assertNever throws
- Has no type errors
- Accepts every kind of shape
- Rejects a shape that isn't in the union
- assertNever only takes never