Report #70801
[bug\_fix] Object literal may only specify known properties, and 'extraProp' does not exist in type 'Config'. \(TS2322\)
Use a type assertion \(e.g., \`as Config\`\) if the extra properties are intentional and safe, or assign the object to an intermediate variable without the type annotation \(e.g., \`const config = \{ ... \}; func\(config\);\`\) to bypass excess property checking. Alternatively, add the property to the interface definition or use an index signature \`\[key: string\]: any\` if arbitrary properties are valid. Root cause: TypeScript performs "excess property checking" \(freshness checking\) on object literals assigned to typed locations \(variables, parameters, return values\). This check ensures that object literals do not specify properties not explicitly declared in the target type, catching typos and incorrect assumptions about interfaces. This check only applies to "fresh" object literals written inline; assigning a pre-existing variable bypasses the check because the object may have been created for other purposes.
Journey Context:
You're developing a configuration-driven feature where you have an interface \`AppConfig\` with specific fields like \`apiUrl\` and \`timeout\`. You create a helper function \`initializeApp\(config: AppConfig\)\`. You call it with an object literal: \`initializeApp\(\{ apiUrl: "...", timeout: 5000, retryCount: 3 \}\)\`. TypeScript immediately flags \`retryCount\` with "Object literal may only specify known properties, and 'retryCount' does not exist in type 'AppConfig'". You think "But the function will just ignore extra properties, and I want to pass this for future-proofing\!" You try casting the whole object to \`any\` which works but removes all type safety. You try assigning the object to a variable first: \`const cfg = \{ apiUrl: "...", timeout: 5000, retryCount: 3 \}; initializeApp\(cfg\);\` and suddenly TypeScript accepts it without error\! You investigate and discover the concept of "excess property checking" - a special freshness check that only applies to object literals written directly in the typed position. By assigning to an intermediate variable, the object is no longer "fresh" and is only checked for assignability \(structural typing\), not excess properties. You decide whether to use this technique, add \`retryCount\` to the interface, or use a type assertion, understanding exactly why TypeScript was complaining.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T01:25:19.375705+00:00— report_created — created