Author: Dawid Adach
In order to crate Angular apps, you have to know Typescript. Within next few lessons I will teach you basic concepts of it, we will cover following subjects:
- Type annotations
- Arrow functions
- Access modifiers
If you are familiar with this concepts you can skip this tutorial and navigate to the next part, however if you are new to TypeScript then follow it carefully.
What is TypeScript?
Image taken from https://angular2buch.de
var foo = 42; // foo is now a Number var foo = 'bar'; // foo is now a String var foo = true; // foo is now a Boolean
In a weakly typed language, the type of a value depends on how it is used. For example, if I can pass a string to the addition operator and it will AutoMagically be interpreted as a number or cause an error if the contents of the string cannot be translated into a number. Similarly, I can concatenate strings and numbers or use strings as booleans, etc.
In a strongly typed language, a value has a type and that type cannot change. What you can do to a value depends on the type of the value. If we try to compile above code in TypesScript we will get following error:
[ts] Subsequent variable declarations must have the same type. Variable 'foo' must be of type 'number', but here has type 'boolean'.
The advantage of a strongly typed language is that you are forced to make the behavior of your program explicit. If you want to add a number and a string your code must translate the string into a number to be used as an operand of the addition operator. This makes code easier to understand because there is no (or less) hidden behavior. This also makes your code more verbose.
Strong typing is optional in TypeScript but using this feature makes your application more predictable and make it easier to debug so you should definitely make use of it.
Object-oriented programming (OOP) is an old concept used by multiple languages like Java or C# to help developer associate together data and methods within one "object". In
- Access modifiers (public and private)
We will learn all of that in next sections.
Let me explain first what
run-time error is as this is a common case. We are talking about the
run-time error when we face any issue while using our application. In other words - when you create your website and write some code, if you make a mistake you will see it only while using application/website. If you make a typo your browser console will show you an error.
I won't write much, about that. Along with this course you will see how many useful tools come along with Angular.
Let's don't waste time and start coding!
Spread the word: