Report #17255
[bug\_fix] TS2322: Type '\{ name: string; extra: number; \}' is not assignable to type 'Person'. Object literal may only specify known properties, and 'extra' does not exist in type 'Person'.
TypeScript performs "excess property checks" specifically on object literals being assigned to typed variables or passed as arguments. This check only applies to "fresh" object literals written directly in the code, not to objects stored in variables. The purpose is to catch typos or incorrect object shapes at the point of creation. To fix a legitimate case where extra properties are needed temporarily \(e.g., for debugging or intermediate objects\), either remove the excess property, use a type assertion \(e.g., \`as Person\`\), or assign the object to an intermediate variable first to bypass the freshness check.
Journey Context:
Developer defines an interface \`interface Person \{ name: string; age: number; \}\`. They then write: \`const p: Person = \{ name: 'Alice', age: 30, gender: 'F' \};\`. TypeScript immediately highlights \`gender\` with error TS2322, stating that \`Object literal may only specify known properties, and 'gender' does not exist in type 'Person'\`. The developer is confused because TypeScript is structurally typed, and they know that if they did \`const temp = \{ name: 'Alice', age: 30, gender: 'F' \}; const p: Person = temp;\`, it would compile without error. They search and learn about "excess property checks," a special freshness check for object literals that helps catch typos \(e.g., \`nam: 'Alice'\`\). They realize the check is only for literals assigned directly. To fix, they can remove the \`gender\` property if it was a mistake, or if they genuinely need the extra property for later processing but want to satisfy the type checker for now, they either cast: \`\{ ... \} as Person\`, or use an intermediate variable to bypass the check.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T04:51:44.999700+00:00— report_created — created