First Lesson was just a flash about TypeScript – today I will try to show you possible types and their valid and wrong values.
In TypeScript types are categorized as primitive types, object types, union types, or type parameters;
Primitive types are:
Let’s see possible values for this types
As we can see, we can’t assign string to number or number to bool etc – so we finally get it!
Interesting detail is that we can declare variable as void – but we can’t assign value. Void types are for function and methods – just for information that we shouldn’t expect any return value;
We might consider disallowing declaring variables of type Void as they serve no useful purpose. However, because Void is permitted as a type argument to a generic type or function it is not feasible to disallow Void properties or parameters.
For every primitive we can assign undefined or null.
For all primitive types we have mother – any (like Object in Java).
That’s why it’s possible to assign different types to variable with static constraint any.