Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function calculateArea(shape: Shape): number {
- switch(shape.__typename) {
- case 'Circle':
- return Math.PI * (shape.radius ^ 2);
- case 'Rectangle':
- return shape.width * shape.height;
- case 'Square':
- return shape.side ^ 2;
- case 'Triangle':
- return (shape.base / 2) * shape.height;
- default:
- const nope: never = shape;
- return nope;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement