There are two kind of types in TS. Primitive and User Defined type.
Any
TypeThe any data type is the super type of all types in TypeScript. It denotes a dynamic type. Using the any type is equivalent to opting out of type checking for a variable.
The keyword is number
. It represents both integer and floating point number.
The keyword is string
.
Keyword is Boolean
. Values are true
and false
.
Keyword is void
. Used as return type in function that returns nothing. Should not use in the function declaration if the function returns anything.
Keyword is null
. It means nothing, no value at all, nothing, empty or whatever that makes sense to you.
Keyword is undefined
. Variable that initilized with no value gets assigned with undefined
. It means the value is unknown.
The null and the undefined datatypes are often a source of confusion. The null and undefined cannot be used to reference the data type of a variable. They can only be assigned as values to a variable.
However, null and undefined are not the same. A variable initialized with undefined means that the variable has no value or object assigned to it while null means that the variable has been set to an object whose value is undefined.
User-defined types include Enumerations (enums), classes, interfaces, arrays, and tuple. These are discussed in detail in the later chapters.