0
0
Typescriptprogramming~5 mins

Interface vs type alias decision in Typescript - Quick Revision & Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What is a key difference between an interface and a type alias in TypeScript?

An interface can be extended or implemented multiple times, allowing declaration merging, while a type alias cannot be reopened once declared.

Click to reveal answer
beginner
Can a type alias represent union or intersection types in TypeScript?

Yes, type aliases can represent complex types like unions (|) and intersections (&), which interfaces cannot directly express.

Click to reveal answer
intermediate
When should you prefer using an interface over a type alias?

Use interface when you want to take advantage of declaration merging or when defining object shapes that might be extended or implemented by classes.

Click to reveal answer
beginner
Is it possible to use a type alias to define a function signature in TypeScript?

Yes, type aliases can define function types, for example: type Fn = (x: number) => string;.

Click to reveal answer
intermediate
What happens if you declare two interfaces with the same name in TypeScript?

TypeScript merges the declarations, combining their members into a single interface.

Click to reveal answer
Which of the following can be extended by other declarations in TypeScript?
ABoth interface and type alias
BType alias
CInterface
DNeither interface nor type alias
Which can represent a union type in TypeScript?
AInterface
BNone
CBoth
DType alias
If you want to define a function type, which is the best choice?
AInterface
BType alias
CEither interface or type alias
DNeither
What happens when two interfaces with the same name are declared?
AInterfaces are merged
BThe second interface overwrites the first
CError: duplicate interface
DOnly the first interface is used
Which is NOT true about type aliases?
AThey support declaration merging
BThey cannot be reopened once declared
CThey can define function types
DThey can represent primitives, unions, intersections
Explain when you would choose an interface over a type alias in TypeScript.
Think about reusability and extension features.
You got /3 concepts.
    Describe the capabilities of type aliases that interfaces do not have.
    Focus on complex type expressions.
    You got /4 concepts.