TypeScript · Senior · Question 47 of 75

Why is extending an interface faster for the compiler than an intersection?

Explanation

The compiler caches the result of comparing interfaces by name, while an intersection A & B & C has to be normalized and compared structurally every time. In hot paths with large types this is noticeable. The TypeScript performance wiki says so explicitly.

Further reading

Problem with a question

TypeScript · Senior · question 47

Test yourself

Take the TypeScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz