Left ArrowBack

notes / JavaScript / typescript


A square with the letters 'TS'.


Last Tended

Status: seed

TypeScript is a strongly typed programming language that builds on JavaScript.

A man modifying a gun using a holographic HUD (heads-up display).


TypeScript provides the following advantages over vanilla JavaScript:

  • self-documentation,
  • tooling that can be built on top of it, improving developer experience (example: IntelliSense) &
  • through static analysis, it eliminates an entire class of runtime bugs (example: where a function gets passed an object it doesn't know how to handle and fails at runtime).
An empty circle with a line through it.

Don't Use Enums

Execute Program did a great break down of the benefits of using unions instead of enums. Their main argument is TypeScript is supposed to be JavaScript, but with static type features added. If we remove all of the types from TypeScript code, what's left should be valid JavaScript code. Imagine we had this TypeScript code:


function add(x: number, y: number): number {
  return x + y;

To compile, the compiler checks the code's types. Then it needs to generate JavaScript code. In this example, that would be removing all type annotations:


function add(x, y) {
  return x + y;

Enums break this rule. If enums were removed like other type features, you would have JavaScript code referencing nothing:


enum HttpMethod {
  Get = 'GET',
  Post = 'POST',

const method: HttpMethod = HttpMethod.Post;
method; // Evaluates to 'POST'


const method = ???;

I agree with Execute Program. I don't believe the benefits of enums outweigh the complication they add to the TypeScript complier model & the possibility of difficult bugs hidden in build steps.

A space ship's docking bay with various equipment.


People to Follow
Matt PocockBuilding Total Typescript

Where to Next?

A sci-fi robot taxi driver with no lower body