0
0
Typescriptprogramming~5 mins

Why type aliases are needed in Typescript - Quick Recap

Choose your learning style9 modes available
Recall & Review
beginner
What is a type alias in TypeScript?
A type alias is a way to give a new name to a type. It helps make complex types easier to read and reuse.
Click to reveal answer
beginner
Why do we need type aliases instead of repeating types everywhere?
Type aliases reduce repetition and make code easier to maintain. If a type changes, you only update it in one place.
Click to reveal answer
beginner
How do type aliases improve code readability?
By giving meaningful names to complex types, type aliases make code easier to understand at a glance.
Click to reveal answer
intermediate
Can type aliases represent union types? Give an example.
Yes. For example, type Status = 'success' | 'error' | 'loading'; creates a type alias for these string values.
Click to reveal answer
intermediate
What is one difference between type aliases and interfaces in TypeScript?
Type aliases can represent primitive types, unions, and tuples, while interfaces mainly describe object shapes.
Click to reveal answer
What is the main benefit of using type aliases in TypeScript?
ATo execute code faster
BTo give a name to a type for easier reuse and readability
CTo replace variables
DTo create functions
Which of these can a type alias NOT represent?
AHTML elements
BPrimitive types
CFunctions
DUnion types
If you want to change a complex type used in many places, what helps you avoid changing it everywhere?
AClass
BVariable
CFunction
DType alias
Which syntax correctly defines a type alias for a union of string literals?
Alet Direction = 'left' | 'right' | 'up' | 'down';
Binterface Direction { 'left' | 'right' | 'up' | 'down' }
Ctype Direction = 'left' | 'right' | 'up' | 'down';
Dfunction Direction() { return 'left' | 'right' | 'up' | 'down'; }
Which statement is true about type aliases and interfaces?
AType aliases can represent unions, interfaces cannot
BInterfaces can represent unions, type aliases cannot
CBoth are exactly the same
DNeither can represent object shapes
Explain why type aliases are useful in TypeScript and give an example.
Think about how naming a type helps when you use it many times.
You got /3 concepts.
    Describe the difference between type aliases and interfaces in TypeScript.
    Consider what kinds of types each can represent.
    You got /3 concepts.