Overview - Excess property checking behavior
What is it?
Excess property checking is a TypeScript feature that helps catch errors when you assign objects with extra properties that are not expected by a type. It happens mainly when you assign an object literal directly to a variable or pass it as a function argument. This behavior ensures that objects match the expected shape exactly, preventing bugs caused by typos or unintended properties.
Why it matters
Without excess property checking, you might accidentally pass objects with wrong or extra properties, causing bugs that are hard to find. This feature acts like a safety net, alerting you early when your object has unexpected properties. It helps keep your code more reliable and easier to maintain, especially in large projects where many objects and types interact.
Where it fits
Before learning excess property checking, you should understand TypeScript's basic type system, especially object types and interfaces. After this, you can explore advanced type features like type inference, type guards, and mapped types to write even safer and more flexible code.