- 4 years ago
- Afaq Arif
- 2,361 Views
-
3
In this chapter, we will learn about TypeScript Types.
The Type System shows various types of values supported by the language. It tests the validity of the supplied values before they are controlled by the program. This guarantees us that the code will act as expected. We can also do richer code hinting and automated documentation through The Type System.
TypeScript gives data types as a component of its optional Type System. The data type classification is as given below.
The Any type
The any data type is the supertype of all TypeScript types representing a dynamic type. If you use any type, then it will be identical to choosing out of type checking for a variable.
Built-in types
The following table represents all the built-in types in TypeScript.
Data type | Keyword | Description |
---|
Number | number | Double precision 64-bit floating point values. It can be used to represent both, integers and fractions. |
String | string | Represents a sequence of Unicode characters |
Boolean | boolean | Represents logical values, true and false |
Void | void | Used on function return types to represent non-returning functions |
Null | null | Represents an intentional absence of an object value. |
Undefined | undefined | Denotes value given to all uninitialized variables |
Note − There is no integer type in TypeScript and JavaScript.
Null and undefined ─ Are they the same?
The null and the undefined datatypes are sometimes confused us. We can not use both to reference the data type of a variable. They can only be given as values to a variable.
However, null and undefined are not the same. A variable instated with undefined means that it 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
User-defined types include Enumerations (enums), classes, interfaces, arrays, and tuple. We will discuss them in detail in the later chapters.
- 4 years ago
- Afaq Arif
- 2,361 Views
-
3