Recall & Review
beginner
What is a type alias in TypeScript?
A type alias gives a new name to a type. It helps make code easier to read and reuse by naming complex types.
Click to reveal answer
beginner
How do you create a union type alias in TypeScript?
Use the
type keyword followed by a name, then an equals sign, and list types separated by |. For example: type MyUnion = string | number;Click to reveal answer
beginner
What does the union type
string | number mean?It means a value can be either a string or a number. The value must match one of the types in the union.
Click to reveal answer
intermediate
Why use a type alias for unions instead of writing the union everywhere?
It makes code cleaner and easier to update. If the union changes, you only update the alias once instead of many places.
Click to reveal answer
intermediate
Can type aliases be used with complex unions like objects and primitives?
Yes! You can create aliases for unions of any types, including objects, primitives, or even other type aliases.
Click to reveal answer
Which syntax correctly defines a type alias for a union of string and number?
✗ Incorrect
The correct syntax uses 'type' keyword and '|' for union. So 'type MyType = string | number;' is correct.
What does the union type alias
type Status = 'success' | 'error' | 'loading'; represent?✗ Incorrect
The union lists specific string literals, so the value must be one of those exact strings.
Why might you use a type alias for a union type?
✗ Incorrect
Type aliases help simplify code and make updates easier by naming complex types.
Which of these is NOT a valid union type alias?
✗ Incorrect
'&' is intersection, not union. The question asks for union type alias.
Can a type alias for a union include other type aliases?
✗ Incorrect
Type aliases can be combined and reused inside unions freely.
Explain what a type alias for a union is and why it is useful in TypeScript.
Think about naming a group of types together.
You got /3 concepts.
Write a simple example of a type alias for a union of string literals representing colors.
Use single quotes for string literals.
You got /3 concepts.