Report #91129
[bug\_fix] Object literal may only specify known properties, and 'extraField' does not exist in type 'InterfaceName'. TS2322
TypeScript performs excess property checking on object literals to catch typos. If the property is intentional but not in the target type, use a type assertion: \(\{ ... \} as InterfaceName\). If the property should be allowed, update the interface to include it, or use an index signature: \[key: string\]: any. To bypass the check without assertions, assign the object to a variable first: const temp = \{ extraField: 1 \}; func\(temp\); because excess property checks only apply to fresh object literals passed directly as arguments.
Journey Context:
You define an interface ApiOptions \{ url: string; method: 'GET' \| 'POST'; \} and a function function fetchData\(opts: ApiOptions\) \{ ... \}. You call it with fetchData\(\{ url: '/api', method: 'GET', timeout: 5000 \}\). TypeScript errors with 'Object literal may only specify known properties'. You didn't mean to pass 'timeout' - it was a typo for 'headers'? No, you actually want to pass extra metadata that the function ignores but you use later. You try adding 'timeout' to ApiOptions but that breaks other call sites. You try fetchData\(\{ ... \} as ApiOptions\) and the error disappears - the type assertion tells the compiler to trust you. Alternatively, you refactor to use a broader type: interface ApiOptions \{ url: string; method: 'GET' \| 'POST'; \[key: string\]: any \} allowing arbitrary extra properties. Or you separate the variable: const options = \{ url: '/api', method: 'GET', timeout: 5000 \}; fetchData\(options\); which bypasses the fresh literal check because the object is no longer considered a 'fresh' literal in that context.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T11:33:25.109384+00:00— report_created — created