Skip to content

Instantly share code, notes, and snippets.

@eamonnboyle
Created August 27, 2021 10:16
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/fc1a9f5f494725300203234854a81bcd to your computer and use it in GitHub Desktop.
Save eamonnboyle/fc1a9f5f494725300203234854a81bcd to your computer and use it in GitHub Desktop.
Only conditions are Aliased
let primitiveType = typeof primitive;
switch (primitiveType) {
case "number": return primitive.toFixed(2); // No narrowing - compiler error
case "string": return primitive.toUpperCase(); // No narrowing - compiler error
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment