Cross Platform

Why TypeScript is better than JavaScript

Pinterest LinkedIn Tumblr

Welcome guys, I gonna explain why TypeScript is better than JavaScript in this blog. It articles for absolute beginners,  We’ll discuss what TypeScript is and how to use it.    

Especially this article is helpful for those whose work on JavaScript and wish to adept at TypeScript. But they just want to know what TypeScript extra provides on top of it. Then you are in the right place.

What TypeScript actually?

  • TypeScript is an open-source language that builds on JavaScript by adding some extra features.
    So it was called the superset of JavaScript. Meaning it’s everything that JavaScript plus some other features. The main feature or reason to use TypeScript is to add static types to your code which I will talk about in this article, using types or any TypeScript features is completely optional, You can create .ts files which is the extension the TypeScript uses and you can have regular JavaScript in this file it will work fine. The reason is that all TypeScript files are compiled down to regular JavaScript.
  • TypeScript is used in the frontend with vanilla JavaScript as well as with frameworks like React, angular, and angular2. It can also be used on the backend as well with node js. As far as features, the obviously biggest feature is having static types but you also have most of the features that include ES6, and ES7, things like classes, arrow functions, etc.   
  • Most of the feature is already included from es6 and es7, things like classes and arrow functions. So the main reason to use TypeScript is static types. 

Dynamic and Static Types 

In the programming world, you have dynamically typed languages and you have statically typed languages

Dynamic types languages

Dynamic typed languages like the types are associated with run-time value, not explicitly named in the code. Meaning that if you create an available let’s say name and assigned value is brad as a string, you don’t specify in JavaScript that variable is a string. Some examples of dynamic types languages are Javascript, Python, Ruby, and PHP

Static Types  languages

Statically Typed Languages you explicitly assign types to variables, whether that’s a string, Boolean, number, functions parameter, functions return value can also have types as well, etc.  

So you will declare types as well, so you declared the same name variables as a string so statically types languages. Some static-typed languages are JAVA, C, C++, Rust, Go,  

Pros and Cons of TypeScript

ProsCons
More Robust More code to write 
Easily spot bug More to learn 
Predicability Require compilation 
Readability Not true static typing 
Popular 

Summary

  • TypeScript makes your code more robust as all variables type defined and this also easily spots bugs in as early stage, that you may miss if you are not using types. 
  • Apparently, research has found that typescript detects about 15 % of common bugs at the compiled stage. Readability is also a good feature especially.
  • Type script uses .ts and  .tsx extensions for working with JSX, Like you are working with react component 
  • For Typescript uses TypeScriptComplier is main tools. That we can use to transpile typescript to javascript.   In simple words, TSC (Typescript compiler) is used to compile .ts file down to js.
  • TSC can watch files and reports error at the compile time. 
  • Many tools include TS compilation by default with needs extra setup for that. 
  • Most IDE have greater support for TS
  • The ts.config file is used to configure how TypeScipts will work. You can create or generate ts.config file to control how TypeDcript works. 

Let learn TypeScript

 

I think that is enough detail to start working on Typescripts. Let’s move on VSCode with spend much time. All right so first thing we can do install the typescripts compiler. 

That we can do this with NPM and yarn and also you can install it globally so it will work with hole system or locally in the project. Will continue this article will some example

Conclusion 

In my opinion, TypeScript is worth learning TypeScript. I am not saying you should use it for every single project. So for me most of the stuff I work I do myself not really really large projects use JavaScript, But In large projects I always prefer TypeScript, because while you are working with multiple developers the code quality matter.

The code should be more expressive, and you can see what going on. If you building simple react applications only then TypeScript is unnecessary stuff, But does my opinion, Of course, you welcome to disagree with that. Thanks for coding with me. Thank You      

Write A Comment