excess property checking
An extra TypeScript check that rejects unknown properties when an object literal is written directly where a type is expected.
In more detail
Normally extra properties are fine under structural typing. But passing { title, slug, wordCount, unpublished } straight to a function expecting Article is flagged, because the extra key is probably a typo. Assigning the same object to a variable first skips the check.
Related terms
- object literal — An object written out in code with curly braces, such as { id: "usr_100", email: "alex@example.com" }.
- structural typing — A type rule where two types are compatible if they have the same shape, whatever they are called.
- interface (TypeScript) — In TypeScript, a named description of an object's shape: which properties it has and their types.
Taught in
- Why TypeScript: Contracts, Erased Types And Soundness — Production TypeScript