Created
August 27, 2021 10:14
-
-
Save eamonnboyle/7c019f82df2c269668c0984956dc088e to your computer and use it in GitHub Desktop.
More Complex Aliased Conditions
This file contains 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
const isDog = animal.kind === 'Dog'; | |
const isCat = animal.kind === 'Cat'; | |
const canSpeak = isDog || isCat; // Also retains CFA information | |
if (!canSpeak) { | |
throw new Error('What does the Fox say?'); | |
} | |
return isCat | |
? animal.purr() | |
: animal.bark(); // Without the throw above this would be `Fox | Dog` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment