Vera
Jul 02, 2022

JS vs Ts

Why was TypeScript Developed Despite Having JavaScript?

JavaScript language was introduced as a client-side programming language. But with the usage of JavaScript for web development, developers learned that it could also be considered a server-side programming language.

However, the JavaScript code became quite complex and heavy, too. Therefore, JavaScript could not be able to stand up to the expectations of an object-oriented programming language. As a result, JavaScript will never flourish as a server-side technology in the industry. This is why the TypeScript language was born to bridge this gap.

What’s TypeScript?

Developed and maintained by Microsoft, TypeScript is an object-oriented, open-source programming language. It’s a superset of JavaScript, containing optional typing. Also, it compiles to plain JavaScript.

In a nutshell, TypeScript is a statically compiled programming language for writing clear and concise JavaScript code. It’s fulfilling the same purpose as JavaScript and can be used for both client-side and server-side applications. In addition, the libraries of JavaScript are also compatible with TypeScript.

TypeScript is a programming language that supports both dynamic and static typing. It provides classes, visibility scopes, namespaces, inheritance, unions, interfaces, and many other features. Also, it offers comments, variables, statements, expressions, modules, and functions.

You can execute it on Node.Js or any other browser that supports ECMAScript 3 or its latest versions.

Since TypeScript is an enhanced version of JavaScript, all code of JavaScript is syntactically valid TypeScript. However, it doesn’t mean the TypeScript compiler can process all JavaScript:

let a = 'a'; a = 1; // throws: error TS2322: Type '1' is not assignable to type 'string'.

TypeScript provides files that can include type data from current object files, similar to how C++ header files define the creation of current object files. Hence, other apps can use the values defined in files just as TypeScript entities with statically typed values.

You will also find third-party header files for popular libraries like jQuery, D3.js, and MongoDB. There are also TypeScript headers for NodeJs elementary modules, which allow Node.Js development within TypeScript.

The compiler of TypeScript is assembled in JavaScript and written in TypeScript. It’s registered under Apache License 2.0.

After going through the TypeScript introduction, you must be wondering what would be the objective of adding static typing to JavaScript?

Well, we can clarify your doubts with the given statements:

As per the study, TypeScript identifies around 15% of all JavaScript errors.

The freedom of dynamic typing frequently leads to errors, which not only reduces the developer’s efficiency but also can grind development due to the increasing expenses of adding new lines of code.

As a result, JavaScript is a poor choice for server-side code in organizations and large codebases due to its lack of types and compile-time error checks.

As their tagline suggests, TypeScript is JavaScript that scales.

Why Do We Need to Use TypeScript?

As we said earlier, TypeScript is an enhanced version of JavaScript. Therefore, while comparing it with other languages like CoffeeScript (which adds syntactic sugar) or PureScript (which is not similar to JavaScript at all), it’s necessary to learn many things to write TypeScript code.

In TypeScript, types are optional, and any JavaScript file is a valid TypeScript file. While the compiler will notify you if any of your initial files have type issues, it will still provide a JavaScript file that works. TypeScript will stand up to expectations, and it’s simple to improve your skills over time.

Osama Megahed

Osama Megahed

this is the first blog to me and I am trying to do my best to make it as better as I can

Leave a Reply

Related Posts

Categories