What types exist only at compile time
📖 Scenario: Imagine you are learning TypeScript to write safer JavaScript code. You want to understand which types help you catch mistakes before running your program but do not exist when the program runs.
🎯 Goal: You will create some TypeScript types that exist only during compile time and see how they help check your code without affecting the final JavaScript output.
📋 What You'll Learn
Create a type alias called
Fruit with exact string values 'apple', 'banana', and 'orange'.Create an interface called
Person with properties name (string) and age (number).Create a variable
favoriteFruit of type Fruit and assign it the value 'banana'.Create a variable
user of type Person with name 'Alice' and age 30.Print the values of
favoriteFruit and user.name.💡 Why This Matters
🌍 Real World
TypeScript types help developers write safer code by catching mistakes early without slowing down the running program.
💼 Career
Understanding compile-time types is essential for frontend and backend developers using TypeScript to build reliable applications.
Progress0 / 4 steps