Skip to content

Instantly share code, notes, and snippets.

@eamonnboyle
Created August 27, 2021 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eamonnboyle/7c019f82df2c269668c0984956dc088e to your computer and use it in GitHub Desktop.
Save eamonnboyle/7c019f82df2c269668c0984956dc088e to your computer and use it in GitHub Desktop.
More Complex Aliased Conditions
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