Created
October 13, 2017 19:53
-
-
Save talentdeficit/349e70028ac08ca55de9b6b67cc4cbde to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function assertNever(x: never): never { | |
throw new Error("Unexpected object: " + x); | |
} | |
function area(s: Shape) { | |
switch (s.kind) { | |
case "square": return s.size * s.size; | |
case "rectangle": return s.height * s.width; | |
case "circle": return Math.PI * s.radius ** 2; | |
default: return assertNever(s); // error here if there are missing cases | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment