Report #14814
[bug\_fix] TS2322: Type '\{ a: string; b: string; \}' is not assignable to type '\{ a: string; \}'. Object literal may only specify known properties, and 'b' does not exist in type '\{ a: string; \}'.
Use a type assertion to bypass excess property checks: \`const obj = \{ a: 'x', b: 'y' \} as \{ a: string; \};\` or assign to an intermediate variable to disable the fresh object literal check: \`const temp = \{ a: 'x', b: 'y' \}; const obj: \{ a: string; \} = temp;\`.
Journey Context:
You're refactoring a legacy JavaScript codebase to TypeScript. You have a function \`saveConfig\(config: \{ host: string \}\)\` and you're calling it with \`saveConfig\(\{ host: 'localhost', port: 3000 \}\)\`. TypeScript throws TS2322 with the specific note 'Object literal may only specify known properties'. You check the function and confirm it only uses \`host\`, but in JavaScript the extra \`port\` property was harmless. You try to fix it by defining an interface \`interface Config \{ host: string; \[key: string\]: any \}\` but that changes the function contract. You search the error message and learn about TypeScript's 'excess property checks' - a special validation that only triggers on fresh object literals assigned to typed variables. This check exists to catch typos in object literals \(like \`nam\` instead of \`name\`\). The fix is to either use a type assertion \`as Config\` to tell TypeScript you know about the extra properties, or assign the object to an intermediate variable first \(which 'stales' the object literal, removing the freshness check\). Understanding that this is a special rule for object literals \(not a structural type system violation\) is key.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T22:26:38.843710+00:00— report_created — created