Created
March 13, 2020 01:21
-
-
Save ksaldana1/00622fb13a9bdbbd170d124fbebde568 to your computer and use it in GitHub Desktop.
gist_3
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