My first contact with Typescript was in 2014 when developers from the open source project called Definitely Typed invited me to help with the visual design of DT. It was an amazing experience and I collaborated with the creation of the logo and the website interface. Some time later Microsoft acquired the project and it is now a famous and official MS open source repository (and the logo I created is until now the official project brand 😁).
But it wasn't until 2018 that I really started learning Typescript because of the React library. Like many developers, I first learned ProtoTypes (a way to add types in React code) and then switched to Typescript - and I fell madly in love with it.
This article will not focus on the technical code, but on the benefits of why TS is awesome. Feel free to take a look at the Typescript documentation at any time.
let name = "Alex", JS will infer the type of variable "name" as string. If we change its value to
name = 6, the type will now be "number". That’s one of the reasons JS is very popular.
But when we have static types, catching errors becomes much easier and most of them will be caught directly in our IDE - before runtime. So if we try to assign a number to a variable that was typed with string we will get an error. And right after fixing the bugs the code will be transpiled. And that greatly improves our productivity and makes our code much safer.
The StackOverflow survey of 2021 shows Typescript is one of the most loved languages.
This another report of 2021 from Github shows Typescript as one of the top languages over the years.
Main advantages of Typescript:
- Use of the new features of JS
- Can be used in both front-end and back-end sides
- Generate cross-browser compatible JS code through its compiler
- Minimal learning curve if you already know JS
- IDE support with code navigation and autocompletion
- And more
I hope I have convinced you that TS is very powerful and useful. But if you haven't learned this language yet, I really recommend learn more about Typescript by reading its documentation and taking this crash TS course if you prefer learn on this way.
Taking the course above I developed this small project to try out all the Typescript features I learned and also explored a lot of Classes and Decorators. Feel free to take a look at it on my Github.
The bigger the project, the greater the need to use Typescript.
Using Typescript doesn't mean that the code will never have bugs, but most of them will be caught before runtime, which will greatly improve the productivity of the team.
Let me know if you already tried TS before and what’s your thoughts about it.
See you next time. 😁