Is Typescript useful and relevent?

IS IT USEFUL TO LEARN TYPESCRIPT IN 2020? IS TYPESCRIPT REALLY A WONDERFUL LANGUAGE AS MANY CLAIM IT TO BE? HOW DOES TYPESCRIPT HELP IN LARGER PROJECTS?


What is Typescript?

The definition of typescript in https://www.typescriptlang.org/ says “TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.”. To make it more understandable, Typescript is simply a Javascript framework that concentrates more on following the standard rules of programming with Static Typing support.

Typescript can be used with Node.Js or any browser that supports Javascript EcmaScript 3 or above which most modern browsers do including Internet Explorer ( No kidding here ).

Typescript provides static typing, classes, interfaces and other standard paradigm that helps in ease of Developement.

Below is the trend that shows how Typescript performs with respect to Javascript

Google Trends – Reference https://trends.google.com/trends/explore?
cat=31&q=Typescript,Javascript

From the above trends its clear that there is a steady usage of Typescript and not many developers out there use Typescript and many developers prefer Javascript over Typescript. But wait don’t jump to conclusion yet.


Is Typescript Useful?

This is a highly subjective question. Typescript preference depends on the developer and his choice of language. Developers who prefer languages like C, C++, Java will definitely prefer Typescript as Static Languages and Typing help in reducing the developmental bugs.

So what do we mean by developmental bugs. Consider the below code.

let name = 'jsschools';
console.log(Name);

Or

let object = {
	name: 'jsschools',
    href: 'jsschools.com',
};
console.log(object.src)

In all the above code We are simply making a typing error which results in a serious problem. This many sound silly now but consider a project which spans across 1000’s of files.

Finding the problem is definitely impossible until we execute the program and arrive at the particular point of failure. Many would argue that the modern IDE’s or Text editors like Visual Studio Code can solve this problem but in most cases they are dumb as Javascript is not typed and the intelisense cannot be used. This makes typing essential part of a large programs. Consider the below Javascript code.

let func = (str) => {
 	console.log(str.toLowerCase());
}
    
func(1)

The above code will result in a error as we are passing a number to a function which expects a string. No IDE will catch this error and will go unnoticed until execution

Uncaught TypeError: str.toLowerCase is not a function
    at myFunction (<anonymous>:4:17)
    at HTMLButtonElement.onclick

Typescript solves these type of programming errors elegantly.


When to use Typescript?

So when should i use Typescript is a big question that haunts developers. My opinion would be to use it whenever possible but lets see the general guideline.

  1. When you are dealing with a third party API which has a NodeJS typescript supported SDK, Typescript can make the life very easy on parsing the response of various uris or when sending a request to the uri, Typescript would let us understand what are the parameters that the uri expects. We will have to refer the documentation if otherwise.
  2. When dealing with Frameworks that are developed over Typescript such as Angular/NestJs, Its advisable to use Typescript though these frameworks support development with plain Javascript.
  3. Whent the program is large and you are working on a critical one where you cannot afford a small error.

When not to use Typescript?

There is literally nothing that could stop you from using Typscript except when the  Javascript framework in use doesn’t support it ( In this case its best to avoid such frameworks as most popular frameworks have Typescript support either officially or through 3rd Party d.ts files.

But we could avoid Typescript in some cases.

  1. Casual Projects
  2. Small Projects ( Small is a relative word and I leave the judgement on the project to the reader )
  3. When its essential to use a framework that doesn’t support Typescript yet

Conclusion:

Typescript is definitely a very good addon to Javascript development. It highly promotes good programming practices and Typing could be handy when dealing with large projects or data.

Learning Typescript is a very good addon to the skillset and one would definitely enjoy Typescript as we get used to the language.

I personally prefer Typescript over plain Javascript any time even in a smaller projects which i do but this is highly subjective and the reader can decide on the use of it.

Leave a Comment