Types

There are two kind of types in TS. Primitive and User Defined type.

The Any Type

The 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.

Primitive Type

Number

The keyword is number. It represents both integer and floating point number.

String

The keyword is string.

Boolean

Keyword is Boolean. Values are true and false.

Void

Keyword is void. Used as return type in function that returns nothing. Should not use in the function declaration if the function returns anything.

Null

Keyword is null. It means nothing, no value at all, nothing, empty or whatever that makes sense to you.

Undefined

Keyword is undefined. Variable that initilized with no value gets assigned with undefined. It means the value is unknown.

Null Vs Undefined

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 Data Types

User-defined types include Enumerations (enums), classes, interfaces, arrays, and tuple. These are discussed in detail in the later chapters.