What is TypeScript?
If you’re coming from an object-oriented language like C# or Java, you’ll find many familiar features in the list that TypeScript adds. My favorites include adding enums, interfaces, access modifiers, namespaces, generics, and more.
TypeScript is great for rich web applications because you can use it to write frontend and backend code. On the backend, you need to install a library called ts-node to run TypeScript code in a Node.js environment.
In 2022, TypeScript was included in the top 5 most used languages worldwide. This isn’t surprising given that TypeScript is always evolving, adding new features, and has a fantastic developer community that the TypeScript team listens to.
When used in pairs with a newer IDE like Visual Studio Code, TypeScript offers great intellisense features like code hinting and code completion. These features help increase the speed of program development.
Also, TypeScript allows the use of some ES6 and ES7 candidate features that are not yet supported by major browsers. For example, the optional concatenation operator and class constants were available in TypeScript long before ECMAScript officially supported them.
Although TypeScript offers several advantages, it also comes with some disadvantages. Neither of these downsides are deal-breakers, but a new developer needs to be aware of them and take them into account.
Another disadvantage of TypeScript is the additional compilation step required. This step can slow down build time and make the bundler more difficult to set up.
Because TypeScript adds many new features that may be unfamiliar to a front-end developer, it increases a codebase’s learning curve. In fact, when used to its full potential, TypeScript can be difficult to understand for untrained developers and require a lot of Googling or mentoring from older teammates.
Finally, some developers complain that using TypeScript requires adding a lot of extra code to define the types. While this is true, it saves time in the long run because it’s easier to onboard new project members. It also makes codebase refactoring easier.
When should you use TypeScript for a new project?
Adopting a new technology that you are new to can be daunting. With TypeScript, however, it’s worth trying as the pros outweigh the cons.
When working on a project with teammates, the decision is more complex as it requires team and management approval. Although using TypeScript will ultimately help your team, it will slow down development in the short term. Also, the team must be willing to spend some time learning TypeScript, its features, and its best practices. Here, an experienced teammate using TypeScript or another object-oriented programming language (like C#) will help the team make a smooth transition.
If your team is willing to sacrifice short-term performance hits and initial time learning TypeScript, I recommend using TypeScript in your project. You will not regret it.
When should you not use TypeScript for a new project?
While TypeScript is generally awesome, there are still reasons I wouldn’t recommend using it.
The number one reason not to use TypeScript is when you or your team have a tight deadline to meet. Deadlines are stressful enough, and adding new technology that you’re inexperienced with isn’t recommended. Unfortunately, learning TypeScript takes time, and that time could be better spent elsewhere on projects with a deadline.
Also, configuring TypeScript can be tricky, especially for beginners. It may be necessary to install several npm libraries and work with a bundler (like webpack). If you’re not willing to spend the time learning all this new information, don’t use it.
Another thing to consider is that using TypeScript raises the developer’s barrier to entry. If the project is open source, this can increase the difficulty for developers to contribute to it.
Also, for managers and hiring staff, using TypeScript in a project means that the developers you hire must have experience using TypeScript or some other Oops Language. Introducing TypeScript raises the minimum skill set to work on the project and may increase the project’s budget as you need to hire more experienced developers.
.tsand fixing the errors thrown by the TypeScript compiler.
Another option is to keep the old code and only write new functions in TypeScript. If a feature touches some legacy code, you can migrate it at the same time as you work on it.
Even though it has some downsides like the extra code complexity or the extra compile time, it saves you time in the long run.
If you work alone, I highly recommend building your next application with TypeScript.
If you’re working with a team, adopting TypeScript might take some convincing. I encourage you to start building a TypeScript project in your free time. You can then show it to your teammates and explain all the benefits of TypeScript.