Report #13450
[bug\_fix] Type '\{ a: string; b: number; \}' is not assignable to type 'TargetType'. Object literal may only specify known properties, and 'b' does not exist in type 'TargetType'
Assign the object to an intermediate variable before passing it to the function \(\`const opts = \{ a: 'x', b: 1 \}; fn\(opts\);\`\). This bypasses TypeScript's excess property check, which only applies to fresh object literals. Alternatively, add an index signature to the target interface or use a type assertion.
Journey Context:
Developer is refactoring a React component or an options object for a function. The interface is \`interface Props \{ name: string; \}\`. They call the component with \`\` or \`myFunc\(\{ name: "test", age: 30 \}\)\`. TypeScript throws an error about 'age' not existing in the type. The developer is confused: "I'm just passing extra data, why does TS care? It should just ignore it." They try to fix it by changing the interface to extend a record or add \`\| any\`, losing type safety. They search and find it's the "excess property check." They learn this check only fires for object literals assigned directly. They test assigning to a variable first \`const opts = \{ name: "test", age: 30 \}; myFunc\(opts\);\` and the error vanishes. They realize the check is a lint-like feature to catch typos \(e.g., \`nmae\` instead of \`name\`\), not a constraint on object shapes at runtime, understanding the heuristic nature of the assignment check.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T18:46:40.830603+00:00— report_created — created