Why Developers Love to Use TypeScript in 2021?

By Saurabh Barot   |   19 July, 2019
Why Developers Love to Use TypeScript in 2021?

Stack Overflow Developer Survey was conducted in 2018 and this revealed several public opinions regarding different programming languages, platforms, libraries, etc. Based on this study, it was seen that when compared with JavaScript, the more loved programming language was TypeScript. Something that makes developers to go for TypeScript is that it simply allows adding types to JavaScript.

This way, before you run the codes, you will be able to spot errors. Moreover, you will also get a better idea about how you can resolve the errors which are provided by the TypeScript compiler.

The developer also gets to use some advanced features from the code editors like automatic module importing, code completion and refactoring across the project when types are added to JavaScript.

TypeScript is just a layer over JavaScript. TypeScript comes with a steep learning curve and learning its syntax before you get started will help you get into programming quickly.

With TypeScript, you can easily convert JavaScript file to it and this can be achieved simply by changing the file extension to .ts from .js. Once it is done, all the JavaScript codes will get compiled to TypeScript.

What is TypeScript?

In the actual sense TypeScript is a programming language. It is also called as the superset of JavaScript. All the functionalities that you will find in JavaScript are available in TypeScript. This can be used for the programming of JavaScript applications which large.

Something that will please you is to know that the latest version of ECMAScript gives you access to TypeScript. You will be able to get a version of JavaScript when you compile TypeScript and it will be safe across all the platforms.

Popularity of TypeScript

If we look at the journey of TypeScript from 2016 to 2018, you will see that the number of users who have used TypeScript and are willing to use again has increased from 20.8% to 46.7%. One of the main reasons why developers choose it is that it is prone to fewer errors.

TypeScript popularity is growing stronger day-by-day, confirms the stats give here;

 

TypeScript enjoys

51,460

Stars on GitHub

TypeScript enjoys

7086

Forks on GitHub

Typescript Holds

6,442,469

Weekly Downloads on NPM

TypeScript Vs JavaScript in 2021

TypeScript is now in the market for a few years and over time new versions have been released that boosted improvements. These improvements were seen in terms of features, functions, performance, etc. The use of TypeScript over JavaScript has increased in the market now. To know it well, you need to have a fair idea about the technologies.

So let’s compare them…

Comparison JavaScript TypeScript
Usage JavaScript is a scripting language which follows client-side programming. It is used to develop interactive web pages. This means without needing anything from the web browser, and it easily runs on the web browser of the user. TypeScript is a development language based on JavaScript. It is used to write simple JavaScript code and this code can be run on any browser which offers support for ECMAScript 3 or the versions newer to it.
Data Binding In JavaScript there is no concept of describing data with interfaces and types. TypeScript makes use of interfaces and types to describe the data.
Ecosystem In case of JavaScript, you can code without having any kind of build step. TypeScript comes with an intuitive ecosystem. This way, you can have some of the JavaScript features included in your project.
Learning Curve JavaScript is easy and flexible. TypeScript comes with a stiff learning curve.
Prototyping Prototyping is absent in case of JavaScript. TypeScript comes with the feature of prototyping.
Code Compilation You don’t need to compile the code in TypeScript. You need to compile the code in TypeScript.
Annotation No annotations are needed in JavaScript. Developers need to annotate their code constantly best output.

Looking to Hire
Professional JavaScript Developers?

Check In & Save Big Bucks

Top Features of TypeScript that Developers Enjoy

Unknown Top Type

It was in TypeScript 3.0 that ‘unknown type’ was introduced as a new ‘type-safe’ which is counterpart of ‘any’ type. What differentiate the two ‘unknown’ and ‘any’ is that ‘unknown’ is much lenient that ‘any’ (‘any’ has been the part of TypeScript since 2012). It does much like ‘any’ as you can assign any value to ‘unknown’, though type assertion is significant here as it cannot do anything without it. Besides, you are not allowed to access or call/construct any properties off of an ‘unknown’ type.

Mapped Types on Arrays and Tuples

TypeScript didn’t go ahead with the way of having a new concept when it comes to a mapping over a tuple, rather in TypeScript 3.1 you have mapped object types. This works exactly the way it is supposed to be when interacting with arrays and tuples. This means if you by any means is making use of mapped types like Required or Partial, which already exists, you will see that they work on arrays and tuples automatically. This way, TypeScript can work well for functions which are like Promise.all.

Node.js packages lead to inheritance of tsconfig.json

With the TypeScript version 3.2, you can resolve tsconfig.json from node_modules.TypeScript will look into thenode_modules package when you are trying to reach “extends” field in tsconfig.json.It will go through the folder of node_modules to look for the package of @my-team/tsconfig-base. Before getting further with the package, TypeScript looks for whether tsconfig field is present in package.json and once it finds it, from the field it loads a configuration file. If such a field is not found, then it will go for tsconfig.json. Such a step proves to be useful when handling larger projects.

Const Assertions

A new construct for literal values have been introduced with TypeScript 3.4 and it is called as const assertions. Here in the syntax, in the place of type name it makes use of type assertion with const. By building literal expressions along with const assertions, you can signal the language that the object literals will come with read-only properties or the arrays will possess read-only tuples.

Type-checking for globalThis

The issues with accessing values within the global scope have been a problem with TypeScript and this issue got taken care with TypeScript 3.4. This has been achieved with the support that it offers for type-checking globalThis from ECMAScript. globalThis is nothing but a global variable which works for global scope. This variable offers easy access to the worldwide scope from any environment that you prefer. Again, you need to know that globalThis does not show up two of the global variables namely const and let.

Support for JSX from defaultProps

TypeScript 3.0 comes with support for a new type for the React development within JSX called as LibraryManagedAttributes. This type works as a helper to define changes in the components of prop types before it is used. This way, it becomes possible to have modifications around inferred and provided mappings and props.
You need to make a note that it will not be possible for the compiler to identify the default properties because of the added explicit type annotation as the default properties are inferred from property type of defaultProps.

Benefits of TypeScript

It is an object-oriented language

This object-oriented language comes with features like interfaces, classes, inheritance, modules, etc.

Static typing is optional

TypeScript comes with the optional static type system and it can be considered as one of the main reasons to choose it. You can add types to properties, functions, variables, etc. So before the app even runs, it will help the compiler to display any warnings regarding any potential issues if present. By letting developers know what kind of type APIs need or want, types work as a helping hand when using frameworks and libraries.

Something that you need to remember at this point is that using types is an optional thing. This means that developers are not forced to use any type which they don’t want forcefully by TypeScript. However, it has to be noted that types will prove to be helpful when the apps become huge and complex with time.

Offers support for JavaScript libraries

You can use TypeScript along with the existing Top JavaScript Frameworks & Libraries and other tools and libraries out there.

TypeScript is portable

It is possible for you to run TypeScript on any devices, browsers or operating systems. This makes it easily available across devices turning it to be portable. You can run TypeScript on any environment where you can work with JavaScript.

Fewer bugs

When it comes to front-end development, it is possible for the developers to save enough time if they have some help which can spot any errors made during the programming process. Now it is at this point you need TypeScript. With TypeScript, you can be sure that your codebase will be free from invalid code.

Intellisense

One of the main benefits of using TypeScript for your project is Intellisense which helps with code completion. As the code gets added, Intellisense offers active hints. All the important IDEs in the market today enjoys the support of the facility of code completion which includes Sublime Text, Atom, WebStorm, VScode and this also includes command-line editors.

TypeScript is like JS

The TypeScript code works starting to end in JavaScript. This means you just need to have some understanding of JavaScript to start working with TypeScript. When it comes to code execution, the code written in TypeScript is compiled and converted to JavaScript.

Conclusion

When working with TypeScript, developers have understood how powerful it is when it comes to bringing in improvement in terms of productivity and how you can use it to build reliable and scalable applications. It is quite easy to integrate this language with an existing JavaScript and can be easily used with React, Angular, Node and Vue.

You need to know that JavaScript and TypeScript are on the path of constant evolution and they are in no way competing with each other. They just complement each other and fulfill different needs. So based on what you need from your project, you can choose the right solution.

Looking for
Experienced TypeScript Professionals

Let’s Discuss

Saurabh Barot

Saurabh Barot is co-founder and Experienced Chief Technology Officer at Aglowid IT Solutions. His deep industry experience in Angular, React, Ruby on Rails, PHP, Mean Stack and just to name few, has helped the company reach to a new level. He believes that technology is all about exploring new possibilities. Whatever a mind can think (exception can't be ruled out), technology brings it into reality.

Related Posts