MyPage is a personalized page based on your interests.The page is customized to help you to find content that matters you the most.


I'm not curious

TypeScript: Is It Worth the Effort?

Published on 06 March 19
0
0

Description: Want to get started with TypeScript but not sure if it’s worth it? Here are the pros and cons of the language proven by practice.

TypeScript: Is It Worth the Effort? - Image 1

Is TypeScript Worth Using?

Typescript is a scripting language that is compiled in JavaScript. It’s a Microsoft’s child that managed to gain its own fanbase. A lot of people are opposed to Typescript, however. The main question that people who are starting to work with it have is “Why do I even need it?”

There are a lot of articles that dwell on its many advantages and weaknesses already. This one exists to show you some insights that I drew for myself while developing a rather big application.

The Advantages of TypeScript

Here are the main benefits of the language:

  • Strong typing
  • Code readability
  • An easier transfer from the word of static typing than JavaScript
  • Backward compatibility with JavaScript
  • Wide IDE support

Strong typing

A strong typing in TypeScript allows you to describe properties and methods of objects and classes more fully than with other languages. This makes for an opportunity to stop checking all the arguments incoming in a function or a method. You will probably find this a real timesaver.

Here’s what it used to look like:

TypeScript: Is It Worth the Effort? - Image 2

TypeScript makes this a lot easier:

TypeScript: Is It Worth the Effort? - Image 3

Now, let’s get to the next point. Strong typing really facilitates the following one.

Code readability

As you see in the code snippet above, reading TypeScript code is a lot easier than JavaScript. It doesn’t have the insane amount of lines of code that JavaScript files tend to include.

One of the many things that TypeScript accomplishes is giving you the typing to check the incoming arguments with fewer lines of code. You end up with the code that doesn’t have the unnecessary elements.

Here’s what a JavaScript code might end up looking like, given enough time.

TypeScript: Is It Worth the Effort? - Image 4

Now compare this to what a TypeScript code would look like.

TypeScript: Is It Worth the Effort? - Image 5

It’s like getting the best custom essay writing services US can offer instead of getting your buddy to write it. A lot less of unnecessary text.

In some cases, you can reduce the lines you have to write with abstractions in JS. This doesn’t work in all cases, though. TS is far more advanced in this respect.

An easier transfer to JavaScript from the world of static typing

A lot of people in coding are reluctant to use JS because it seems too chaotic and unpredictable. This is where TS comes into play. It allows you to write JS in a way you can understand easily.

Backward compatibility with JS

This is a very pleasant bonus. Being backward compatible with JS allows you to keep the code you already have and still use TypeScript.

You can experiment with the language without rewriting the whole application, or even write a part of it in TS. You can also transfer a library that you need from JavaScript to this language to save your time.

Wide IDE support

All major IDEs support TypeScript today. This includes IDEA, WebStorm, Sublime, and Atom.

So you can stick to what you know and love instead of changing it. As you see, TS is an easy language to experiment with.

The Drawbacks of TypeScript

Now that you know the upside, let’s get to the downsides of this language. Here they are:

  • Strong typing
  • Compilation
  • Debug
  • What if it goes extinct?

Strong typing

You’ve seen this point in the advantages. What is it doing here? It’s not an error, it can just work against you as well.

The difference between JavaScript and TypeScript is that you have to describe all types for all objects, all classes, all variables, etc. This is unusual for JavaScript and can be a daunting and time-consuming task.

There’s even a bigger problem associated with TypeScript. It’s the migration of already existing solutions to JS. It is possible, but the way it’s done is extremely time-consuming.

You have to create a .d.ts file for every imported JS library. The file should contain all types that are returned and describe all methods.

It may be fast for a small custom library, but imagine what it’s like to create .d.ts for jQuery.

Compilation

TS compiler makes it easier for you because it’s essentially foolproof. It will adjust all the missing commas and misspelled variable names. That’s good, right?

It is, but there’s a problem with compilation. It kills the beauty of core JavaScript because you can’t run it in a browser console directly. It makes the development process slower as you have to spend more time between iterations.

You’ll have to update the compiler as well. TypeScript is changing, and you will probably need to update the compiler or even learn new elements of the language. If it does change that much, you may need to rewrite some of the existing code.

Debug

Any developer needs to know how to debug their code fast. You have to check the code for errors and find new bugs all the time. There’s a lot of guides that describe the process of doing this already. You can find dozens for debugging TS in different IDEs, and it’s not the point of the article.

The main thing about debugging TS is that it’s a hell of a job compared to JavaScript. With JS, you could just put breakpoints in your browser or editor and debug it. With TypeScript, you have to sweat to do it.

What if it goes extinct?

This arguably is the most serious problem with TypeScript. The thing is, the language is appealing because it had the features JS was lacking, like arrow functions. Now that you find many of these things incorporated in JavaScript, why use TypeScript in the first place?

The odds are, all TS features will become the norm for JavaScript. The language will die at that exact moment. If Microsoft drops the project and leaves it for open source, it’s done for.

Sure, it will still exist in the hands of some enthusiasts, but it will never be as big as it used to be. If this happens, you may have to transfer all your TS projects back to JavaScript.

TS is not an easy language to settle on. With this article, you have the insight to make an informed decision.

Related Posts:
Post a Comment

Please notify me the replies via email.

Important:
  • We hope the conversations that take place on MyTechLogy.com will be constructive and thought-provoking.
  • To ensure the quality of the discussion, our moderators may review/edit the comments for clarity and relevance.
  • Comments that are promotional, mean-spirited, or off-topic may be deleted per the moderators' judgment.
 
Awards & Accolades for MyTechLogy
Winner of
REDHERRING
Top 100 Asia
Finalist at SiTF Awards 2014 under the category Best Social & Community Product
Finalist at HR Vendor of the Year 2015 Awards under the category Best Learning Management System
Finalist at HR Vendor of the Year 2015 Awards under the category Best Talent Management Software
Hidden Image Url

Back to Top