Type Aliases in TypeScript
In TypeScript, you can create aliases types. This is done with the type operator.
As an example, let's define another name for the string data type:
type str = string;
Let's declare a variable using our new type:
let test: str = 'abc';
In general, renaming standard types does not bring any practical benefit. Let's look at a more useful example of using aliases.
Application
Let's create a new data type using type union:
type stumber = string | number;
Let's declare a variable with our new type:
let test: stumber;
Let's write a number into it:
test = 123;
Let's write the following line into it:
test = 'abc';
Practical tasks
Create a new type that combines null and undefined.
Create a new type that combines the boolean type, null, and undefined.