Q52: What are Excess Property Checks (Freshness)?
When an object literal is assigned directly to a variable or passed as an argument to a function, TypeScript subjects it to Excess Property Checking, raising an error if unassigned extra properties are detected.
Excess Property Check Trigger
interface Config { title: string }
function setup(c: Config) {}
// Error! Excess property check catches 'extra'
// setup({ title: "App", extra: true });
// Bypassed by assigning to intermediate variable first
const obj = { title: "App", extra: true };
setup(obj); // Valid under standard structural subtyping!💡 Direct object literal assignments trigger freshness checks to catch typos in property names.
Key Takeaways
- Excess property checks catch property name typos in object literal assignments.