Introduction to TypeScript
What does TypeScript offer ?
- Class Based Objects – Another huge advantage is the use of Classes which provides the ability to use true object oriented programming in our applications and prevents use of prototype based objects. It also provides encapsulation, inheritance and modifiers.
- Modularity – It helps make the code more modular.
- ES6 Features – Support for ES6 features is also one of the main reasons for its popularity.
- Syntax – TypeScript provides syntax which is closer to java and other high level languages (Syntactical Sugaring).
TypeScript Compiler (tsc)
- Written in TypeScript itself.
- Compiles .ts files to .js files.
- Installed as an NPM package (NodeJS).
- Supports ES6 syntax.
|It is an Object Oriented Language (Class based)
|It is an Object Based Language (Prototype based)
|Statically Typed language
|Dynamically Typed language
|Does not Support Modules
|Provides Errors at Compile time / during development
|Doesn’t provide Compile time errors
|Takes more time as the code needs to be Compiled
|No need of compilation
Why is TypeScript gaining popularity ?
Why do we use TypeScript ?
- Code quality – Defining data structures in the beginning, using types and interfaces, forces you to think about your app’s data structure from the start and make better design decisions.
- Prevents bugs – TypeScript won’t make your software bug free. But it can prevent a lot of type-related errors. Along with the Clever IntelliSense many browsers and IDEs support direct debugging through Source Maps .
- Active community – TypeScript is getting more and more popular. It’s used by the top tech companies like Google, Airbnb, Shopify, Asana, Adobe, and Mozilla so we can assume that it reaches their expectations in terms of scalability – as they are developing large and complex applications.
“Often the way TypeScript ends up being adopted — in enterprises and start-ups and individual developers — is that you try it on one project and you say ‘wow, this is great!’ and then you start evangelizing and it grows locally in your sphere of influence.”— Anders Hejlsberg (Core Developer TypeScript).
>Welcome To GFG</
Default code has been
loaded into the Editor.
let myString: string;
'Hello from ts'
After Saving the above files we need to transpile the TypeScript Code.
In the terminal, type the following command:
tsc types.js (syntax : tsc filename).
'Hello from ts'
Share your thoughts in the comments
Please Login to comment...