Should You Learn TypeScript?

TypeScript is challenging and beneficial. Should you take the time to learn it?

Published:12/22/2023, 8:03:28 AM

Introduction

TypeScript builds static typing into JavaScript. If you’re on the fence about learning it, this article should help. First, I’ll explain the major deciding factors. Afterward, I’ll list some supplementary reasons. Finally, I’ll give a few of my thoughts on TypeScript.

Major Factors

I see three major factors that can decide if TypeScript is important for you. One is how you’re using JavaScript. Another is whether you plan to keep up with JavaScript frameworks. The final is the scale of your projects.

If you stick to simple functions, avoid frameworks, and work on minor projects, then learning TypeScript might not be very beneficial. However, if you’re making complex functions with various data structures and object shapes, plan to learn new frameworks, and intend to work on larger projects, then learning TypeScript should be in your future. Let’s dive into the why.

JavaScript Complexity

TypeScript takes time to set up. When it’s done, it keeps track of what’s being passed into different functions and helps you with narrowing. For example, a function’s parameter could be null and you forget to account for that. TypeScript will alert you that you’re performing operations on a possibly null object. Even if you’re using only a couple of complex functions, TypeScript’s automated narrowing checks can help tremendously.

Frameworks and Typescript

Teams building frameworks seem to like TypeScript. One of my largest hurdles to learning React was seeing TypeScript everywhere. There were other options, but I learned TypeScript to overcome that hurdle. This helped in the long run, because many frameworks include TypeScript in their documentation by default. You can choose to view JavaScript in the examples, but the type definitions speed up the learning process.

Project Scale

In this context, project scale refers to team size and lines of code. If you’re working with a large team, then TypeScript enforces data cohesion and conformity. TypeScript’s ability to check arguments for function invocations helps tremendously if you’re placing the same function in multiple places. If you make a variety of simple functions, then TypeScript’s automatic narrowing checks save a lot of time writing and debugging code.

Supplementary Factors

There are a few supplementary factors that may influence your decision. TypeScript can change how you think about data, provide a mental challenge, and prepare you for learning other strongly typed languages. Most of these benefits won’t have the same direct application to your work. However, they can help you become a better web developer and programmer overall.

New Perspective on Data

You can define data in very specific and creative ways with TypeScript. For example, after using TypeScript, you may think about whether an object’s keys should be strings or symbols. Another great thing it can introduce into your toolset is the discriminated union - if you have a lot of objects with slight variations, then you can add a property to each with a value defining what type of object it is. Now, you can create a function that performs duties on their shared properties. The object-defining property gives you an efficient way to narrow and perform operations on properties that exist only for that version. TypeScript can expand the way you think about data.

Challenging Yourself

Learning TypeScript was a significant challenge for me. There are two reasons for this.

The first is TypeScript is an intangible language living within your editor. It gets stripped out during build time. As a result, you’re required to use what’s in JavaScript to make sure your code gets along with TypeScript.

Another substantial challenge with TypeScript is its Generics. If you’re not familiar with TypeScript, you may struggle to understand this. If so, get passed it and understand Generics are challenging.

Generics are functions that inject variables in your type definitions. You can do a lot with them. For example, you can make a Union of all of your API endpoints. Afterward, you create an APIResponseObject Generic that requires one argument. That Generic checks the argument, makes sure it matches one of the API strings in the union, and if so, determines what exact object shape you’re looking at based on the endpoint. Whenever you’re making or invoking functions, you can use APIResponseObject with the endpoint argument to clarify which exact object you’re working with.

Generics are a tough concept to grasp. Learning them will help you pick up other difficult concepts. I’m still learning about TypeScript. My next goal is to learn more about ‘infer.’

Note: While TypeScript and Generics are robust, they can lead to overuse. This makes interpreting your types difficult and can slow your machine down. Because Typescript can lead to overcomplexity, you’ll get better at deciding which techniques, strategies, and patterns are necessary in different situations.

Learn Typed Languages Easier

If you’d like to expand into software programming, then learning TypeScript would be beneficial. Static typing is an intrinsic part of all leading programming languages other than Python. This includes recent and upcoming languages such as Kotlin, Rust, and Carbon. If you have experience and familiarity with static typing, you’ll have a smoother transition into software programming.

My Concluding Thoughts

I love static typed languages, and I’m a big fan of TypeScript. Learning it was one of the best decisions I made along this journey. But it isn’t necessary for every project. This website, for example, is a personal blog based on a single subject. Making templates for my blog posts was far more efficient than creating a typing system that made sure I adhered to the structure when I was making a new post. However, if I were to make an ecommerce site that had a variety of products with unique attributes, then I’m more likely to use TypeScript.

TypeScript is a valuable tool used in the proper context, and it can help you in intangible ways. I think most web developers should learn TypeScript, if not for immediate benefit, then for the benefits it could bring in the future.

Contact Me

If you'd like to hire me, acquire my services, inform me of an open-source project, or just talk code, then please use the form below to send me a message.