Why I Love TypeScript
I was happily coding my microservices in CoffeeScript while I heard
that addressed a lot of the issues with the current language. Classes,
arrow functions binding
this, default parameters,
...rest args, and
even more. It took some time for the features to make it into
There were two final nails in the coffin for my CoffeeScript love. The first was tooling; as ES6 became more popular the tools were updated to support it. Linting, testing, code formatting, integrations, and more -- they were all updated to support the latest goodness in ES6. As CoffeeScript's popularity wained, the community did too. This provided even more impetus to switch.
Secondly, the primary author of CoffeeScript took their time in deciding what to do with CoffeeScript's future.
Contributions and updates to CoffeeScript tapered off, until 2017, when a new primary maintainer stepped forward and started updating CoffeeScript to 2.0. Before then, there was much discussion on what to do with CoffeeScript and how to move forward. In a world where CoffeeScript was supposed to compile down to ES3, something every browser could use, why would you have it compile down to ES6? But if ES6 has the tooling to now compile down too, why use CoffeeScript? It was a language stuck in the past, unable to move forward.
So I left.
Having a compiler is really nice. By conforming code to concrete types
the compiler can catch a whole slew of bugs that might be present in the
very good: you don't need to give it that much help for it to know the
right thing. You also don't need to turn it off that much. When
starting projects from scratch I always use
strict mode and put in
effort to have types for all my objects. It allows me to catch many
errors before runtime, saving time and effort.
- Interfaces: Allows you to define the shape of something with needing to concretely define a class. This is a great way to describe JSON responses from the server.
- Enums: A nice way to describe a type without resorting to strings or integers.
- Decorators: These annotations can be used to create powerful new features with minimal effort. Projects like TypeORM make extensive use of these.
Tooling and Community
A language is only as good as its community, and TypeScript has continued to foster an excellent community with great support.
- DefinitelyTyped stepped in and provided a place for types for many projects that didn't support types themselves. This made TypeScript much more approachable and usable.
- Prettier support!
- Testing with Jest.
I'm optimistic about the future of TypeScript and hope it continues to grow. As the community grows it means even more support for the language, and it's exciting to see projects adopt it such as Next.js. I'll continue preaching the virtues of TypeScript as well!