TypeScript · Junior · Question 6 of 75
What's the difference between interface and type for describing an object?
- ✓Correct answer: Both work;
interfacecan be extended by merging, whiletypecan express unions and more - 2
interfaceworks only with classes, whiletypeworks only with primitive types - 3
typeis deprecated and not recommended in new projects at all
Explanation
For objects they're almost interchangeable. Differences: interfaces with the same name merge (declaration merging) and are extended with extends. Type aliases describe unions, tuples, primitives, conditional and mapped types. Many teams use interface for objects and type for everything else.