TypeScript · Middle · Question 34 of 75
Why is interface preferable to an intersection for extending large object types?
- ✓Correct answer:
extendscatches property conflicts and is faster for the compiler - 2Intersections don't support nested objects and arrays
- 3Interfaces exist at runtime, while intersections don't
Explanation
With interface B extends A, a property conflict is an error at the declaration, while an intersection silently produces never. The compiler caches interface relationships, so it's faster in large codebases - as the TS performance wiki recommends.