Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. function calculateArea(shape: Shape): number {
  2. switch(shape.__typename) {
  3. case 'Circle':
  4. return Math.PI * (shape.radius ^ 2);
  5. case 'Rectangle':
  6. return shape.width * shape.height;
  7. case 'Square':
  8. return shape.side ^ 2;
  9. case 'Triangle':
  10. return (shape.base / 2) * shape.height;
  11. default:
  12. const nope: never = shape;
  13. return nope;
  14. }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement