You will often come across Typescript word while working with Angular. The reason behind this is Angular is written in Typescript Language.
What is Typescript?
Typescript is a open source programming language developed and maintained by Microsoft. Adopted by Angular (Google) too.
Like SASS and LESS compiles to CSS or Java Code compiles to Class files.
Obviously, we include the .js file in our HTML pages not the .ts file. No browser understand Type script.
Simple – Typescript adds additional features.
- Optional Static Typing – Primarily useful to catch errors during compile time.
- Organize your code into Classes, Interface and Module with the Object Oriented Support.
- Major IDE like Eclipse, Atom, Web-storm and Visual Studio provides environment to write and catch error as you type.
- Write robust code that is scalable to enterprise level.
Optional Static Typing
So, there is no error in the above code during compile time. But it is very clear that code will break during runtime.
Using Type script, we can add the typing and specific the data type of the Variable.
Now, you can clearly see that Typescript catches the error during compile time and help us fix the code during development time itself.
The major benefits of optional Static typing is to catch the error while compile time.
Remembered I said it is Optional Typing – Let me show you another example.
Below two source code is from Type script which does not catch errors during compile time. Because we can skip the typing as well.
Typescript Code 1:
Above Type script code will break during runtime but not at compile time. As Typing is optional in Type script.
That’s the power of Type script. You can apply the typing to the variable and catch the possible errors during compile time.
Object Oriented Support:
A very good example from Type script itself.
Sample Example from here: https://www.typescriptlang.org/play/
The major advantage of adding Typing and supported with powerful IDE is to write complex code with built in editor auto correcting feature and code refactoring.
This editors will greatly enhance the developers productivity and developer clean code.
List of popular IDE for Typescript:
- Angular is written in Type Script Language.
- Type script add-on features are:
- Strong Typing
- Supports Object Oriented Concepts
- Majority IDE supports Type script.
- Catch errors at Compile time rather Run time.