Excess property checks
Concept and syntax
TypeScript performs extra checks on fresh object literals assigned to a known shape. Passing { width: 3, theme: "dark" } directly to a function expecting only width can trigger an excess-property diagnostic. A previously bound object with compatible required members may be assignable structurally even with extra members. This is not a universal exact-object rule. If extra information is needed, intentionally extend the contract rather than hiding a typo.
Working example
Compile standalone examples in a fresh directory with tsc --strict --target ES2022 --module commonjs --noEmitOnError main.ts, then node main.js.
function area(options: { width: number }): number { return options.width * 2; }const settings = { width: 3, theme: "dark" };console.log(area(settings), area({ width: 5 }));Expected output (one line per log):
6 10Common mistake
Intentionally invalid; check this snippet separately. Do not run it.
function area(options: { width: number }): number { return options.width * 2; }area({ width: 3, theme: "dark" });Expected compiler diagnostic: TS2353. The fresh literal has a field absent from the expected shape. Remove theme or add it to the intended contract.
Practice and recap
Pass an object with an extra property as a fresh literal and as a previously bound variable. Compare the diagnostic behavior.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Excess property checks — knowledge check
Check the concept, apply it to a new choice, and interpret a compiler diagnostic.
Which form receives an excess-property check in this example?
Does assigning a compatible previously bound object prove it has no extra properties?
Which property is rejected by the fresh-literal check?
function area(options: { width: number }): number { return options.width * 2; }area({ width: 3, theme: "dark" });