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 added by TypeScript. My favorites include adding enums, interfaces, access modifiers, namespaces, generics, and many more.
TypeScript is ideal for large-scale web applications because you can write front-end and back-end code with it. On the backend you need to install a library called ts node to run TypeScript code in a Node.js environment.
In 2022, TypeScript joined the world Top 5 most used languages. It’s no surprise, because TypeScript is constantly developing, adding new features, and has a fantastic community of developers 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 to increase the speed of program development.
By using the
Additionally, TypeScript allows for some candidate ES6 and ES7 features that are not yet supported by major browsers. For example, the optional chaining operator and class constants were available in TypeScript long before ECMAScript officially supported them.
Although TypeScript offers multiple advantages, it also has some disadvantages. None of these disadvantages are decisive, but a new developer should be aware of them and take them into account.
Another disadvantage of TypeScript is the extra compilation step required. This step can slow down the build time and complicate the configuration of the bundler.
Since TypeScript adds many new features that may be unknown to a front-end developer, it increases the learning curve of a code base. Indeed, when used to its full potential, TypeScript can be difficult for untrained developers to understand and requires 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 types. While this is true, it saves time in the long run because it’s easier to onboard new members to the project. It also makes it easier to refactor the code base.
When should you use TypeScript for a new project?
Embracing new technology that you have no experience working with can be daunting. However, with TypeScript, it’s worth it, because its advantages outweigh its disadvantages.
If you’re working on a project with teammates, the decision is more complex, as it requires team and management consent. While ultimately using TypeScript will help your team, it will slow down development in the short term. Additionally, the team should be willing to spend time learning TypeScript, its features, and best practices. This is where having a teammate experienced with TypeScript or another object-oriented programming language (such as C#) will help the team make a smooth transition.
If your team is willing to sacrifice short-term performance hits and upfront time to learn TypeScript, I recommend using TypeScript in your project. You will not regret it.
When should you not use TypeScript for a new project?
Even though TypeScript is generally fantastic, there are still reasons why I wouldn’t recommend using it.
The main reason not to use TypeScript is if you or your team have a tight deadline. Deadlines are stressful enough, and adding new technology that you have no experience working with is not recommended. Unfortunately, learning TypeScript takes time, and that time may be better spent elsewhere on projects with a deadline.
Additionally, TypeScript can be tricky to set up, especially for beginners. This may require installing multiple npm libraries and using 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 will increase the entry threshold for developers. If the project is open-source, it may make it harder for developers to contribute to it.
Additionally, for managers and hiring staff, using TypeScript in a project means that the developers you hire must have experience using TypeScript or another OOP Language. Adopting TypeScript increases the minimum professional qualification to work on the project and may increase the project budget, as you need to hire more experienced developers.
.tsand fixing errors generated by the TypeScript compiler.
Another option is to keep legacy code and only write new functionality in TypeScript. When a feature touches part of the legacy code, you can migrate it simultaneously while working on it.
Even though it has some drawbacks, like the complexity of the code it adds or the extra compilation time, it will save you time in the long run.
If you’re working on your own, I strongly encourage you to build your next app using TypeScript.
If you’re working in a team, adopting TypeScript may take some conviction. I encourage you to start creating a TypeScript project in your spare time. You can then show it to your teammates and explain all the advantages of TypeScript.