Get Start with TypeScript (Introduction & Installation) - Learn


Assalam u alaikum Friends, Hope you will fine here is my first blog on TypeScript and starting of learning point of typescript. 

Watch Tutorial Here:


From today we will learn typescript in very easy way.

Today we will learn:

  • What is TypeScript
  • Difference between TypeScript and JavaScript
  • Installation
  • Execution Policy Error
  • Printing Hello World

What is Typescript?

TypeScript is a strongly typed, object-oriented, compiled language designed by Anders Hejlsberg at Microsoft. It serves as a typed superset of JavaScript, enhancing the language with static type definitions. TypeScript allows developers to describe the shape of objects, providing better documentation and validating code correctness. By adding types, TypeScript simplifies JavaScript code, making it more readable and easier to debug. It introduces compile-time type checking, which helps catch errors before runtime. TypeScript's static typing not only aids in bug detection but also enhances code structure, self-documentation, readability, and speeds up debugging and refactoring processes. This additional layer of type annotations in TypeScript helps developers write more maintainable code and boosts productivity, especially in large projects or when working with distributed teams. The language's evolution and support from a growing community, including major companies like Microsoft, Asana, Lyft, and Slack, instill confidence in its reliability and future development.

Difference between TypeScript and JavaScript

TypeScript and JavaScript have several key differences:

1.Type System: TypeScript is a statically typed superset of JavaScript, allowing for strict static typing as an option, while JavaScript is dynamically typed only.
  
2. Readability and Maintainability: TypeScript is considered more readable and maintainable than JavaScript due to its type annotations and static typing.

3. Abstraction and Features: TypeScript supports features like interfaces, decorators, namespaces, generics, type inference, and more, which are not available in JavaScript.

4. IDE Support: TypeScript offers a more fully-featured IDE experience compared to JavaScript, making it easier to build plugins and tools for a statically typed language.

5. Code Length: TypeScript generally requires writing more code due to type annotations, while JavaScript allows writing less code.

6. Predictability: TypeScript allows developers to easily predict how their code will run due to static typing, while JavaScript may hold more surprises during runtime.

7. Learning Curve: TypeScript has a higher learning curve compared to JavaScript due to its additional features and static typing.

Installation:

Now let's start installation process. Before using typescript you must have Code Editor for typescript we will use best code editor VS Code Download Now if you have not downloaded yet! 
During installation you must tick these both boxes in installation process:



this will help you to quickly open vs code in any folder.
After VS code Installation. Now let's move to install NodeJs. Download Now .

What is NodeJs?

Node.js is a cross-platform, open-source JavaScript runtime environment that allows developers to run JavaScript code outside a web browser. It is built on the V8 JavaScript engine and enables the use of JavaScript for writing command line tools and server-side scripting. Node.js follows an event-driven architecture capable of asynchronous I/O, optimizing throughput and scalability for web applications with many I/O operations and real-time applications like communication programs and browser games.

Node.js is commonly used for building web servers, networking tools, real-time applications like chat rooms and games, data streaming apps, and more. Its ability to handle multiple connections efficiently, along with its event-driven model and non-blocking I/O operations, makes it a popular choice for scalable and high-performance applications.

Install TypeScript

Now search forcmd and open command prompt and type npm install -g typescript and wait for installation completion. After completing verify installation by running command tsc -v  to get version of typescript. If you got version then great! else try again to install. 

Solving Execution Policy Error:



Now let solve this: Search for PowerShell in window search bar and then right click to Run as Administrator then a new window of PowerShell will open then paste this line:

Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy Bypass
and then create a new folder and then right click select open with code then that folder will be open in vs code automatically after vs code launching.
Create a file app.js and then just type console.log("Hello World"); and then save it. Press Ctrl + J to open terminal and then type tsc main.ts and wait for compile to create a JavaScript file. After  compiling you will se a javascript file in your root folder then type node main.js file in terminal after pressing Enter you will see Hello World in console.
Congrats! You done it. Your TypeScript environment is ready and now start practice on typescript.

Download Replit on Android or use on web.

Happy Coding!
Please Subscribe like, share and comment
Previous Post Next Post