Concept Flow - Creating type aliases
Start
Write 'type' keyword
Give alias a name
Assign a type to alias
Use alias in code
End
This flow shows how to create a type alias by naming it and assigning a type, then using it in code.
type Age = number; let myAge: Age = 30; console.log(myAge);
| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Declare type alias 'Age' as number | type Age = number | Alias 'Age' now means 'number' |
| 2 | Declare variable 'myAge' with type 'Age' | let myAge: Age = 30 | myAge is number 30 |
| 3 | Print 'myAge' | console.log(myAge) | Output: 30 |
| 4 | End of code | No more statements | Execution stops |
| Variable | Start | After Step 2 | Final |
|---|---|---|---|
| myAge | undefined | 30 | 30 |
Creating type aliases in TypeScript: - Use 'type AliasName = Type;' syntax - Alias can be primitive, union, or object types - Use alias as a type annotation - Alias is just a new name, not a new type - Helps make code clearer and reusable