Overview - Excess property checks vs structural compatibility
What is it?
In TypeScript, excess property checks are a safety feature that warns you when you add extra properties to an object that are not expected by its type. Structural compatibility means that TypeScript compares the shape of objects to decide if they can be used interchangeably, focusing on matching properties rather than exact types. These two concepts work together to help catch mistakes while allowing flexible use of objects based on their structure.
Why it matters
Without excess property checks, you might accidentally pass objects with typos or unintended extra properties, causing bugs that are hard to find. Without structural compatibility, TypeScript would force exact type matches, making it harder to write flexible and reusable code. Together, they balance safety and flexibility, helping developers catch errors early while writing clean, adaptable programs.
Where it fits
Before learning this, you should understand basic TypeScript types and interfaces. After this, you can explore advanced type features like type guards, mapped types, and discriminated unions to write safer and more expressive code.