TypeScript Setup and Data Types
Explore setting up TypeScript and get a clear understanding of fundamental data types such as strings, numbers, booleans, arrays, and enums. This lesson helps you grasp how TypeScript enforces data type consistency, improving code quality and maintainability in Node.js applications.
We'll cover the following...
Overview
TypeScript is a strictly typed language. It ensures that the data types of variables, return value of functions, class methods, members, and so on are consistent over the lifecycle of our application.
TypeScript data types
Below are the basic data types in TypeScript:
- String
- Number
- Boolean
- Tuple
- Array
- Any
- Void
- Unknown
- Object
- Null
- Undefined
- Never
- Enum
For this lesson, we’ll explore just a few of these.
String, number, and boolean
Declaring a string, number, or boolean variable is as simple, as shown below:
Array
Below, we show how to declare a number, string, or boolean array:
Enum
Enum is a data type that enables us to define standard constants in a way that is easy to remember and maintain. In TypeScript, we have number and string-based enums. We define enums using the enum keyword.
TypeScript provides more data types that aren’t available in JavaScript, which makes developing with TypeScript more professional and maintainable.