Skip to content

Instantly share code, notes, and snippets.

@innocenzi
Last active April 15, 2021 13:58
Show Gist options
  • Save innocenzi/38f955fee4cd26a9fde76f41ab12a118 to your computer and use it in GitHub Desktop.
Save innocenzi/38f955fee4cd26a9fde76f41ab12a118 to your computer and use it in GitHub Desktop.
TypeScript or JavaScript?
// If this code is transpiled by the TypeScript compiler, it will echo "You are using TypeScript"
// If this code is ran as-is, it will echo "You are using JavaScript"
console.log(new Set<String>('1') ? 'You are using TypeScript' : 'You are using JavaScript')
// This is actually valid JavaScript code: properly formatted, it looks like that:
// (new Set) < (String) > ('1')
// In TypeScript, the angle brackets after Set are interpreted as generic types, which is why the result is different.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment