Report #4031
[bug\_fix] Object literal may only specify known properties, and 'colour' does not exist in type 'SquareConfig'.
This is TypeScript's excess property check. Either correct the typo \(e.g., 'colour' -> 'color'\), add the property to the interface definition if it should be valid, or assign the object to an intermediate variable with a wider type \(like \`const config = \{ colour: 'red' \}; createSquare\(config\);\`\) to bypass the check for special cases. Do not use type assertions on the literal itself, as that defeats the safety purpose.
Journey Context:
Developer is interfacing with a library or internal API: \`interface SquareConfig \{ color?: string; width?: number; \}\`. They write \`createSquare\(\{ colour: 'red', width: 100 \}\);\`. TypeScript highlights \`colour\` with "Object literal may only specify known properties, and 'colour' does not exist in type 'SquareConfig'." Developer stares at the code: "But I'm passing a color and width, what does it mean 'excess property'?" They check the interface and realize they misspelled 'colour' \(British vs American spelling\). They fix the typo, error gone. Later, they encounter a case where they genuinely want to pass extra properties for debugging that the interface doesn't care about: \`createSquare\(\{ color: 'red', debugId: '123' \}\)\`. The error returns. They try \`as SquareConfig\` but the error persists on the literal. Down the rabbit hole, they learn about "excess property checks," a special strictness that applies only to object literals fresh off the press. They discover the workaround: assigning to an intermediate variable. \`const config = \{ color: 'red', debugId: '123' \}; createSquare\(config\);\` The error disappears\! Why? Because when the object is assigned to a variable first, TypeScript uses structural typing \(width subtyping\) which allows extra properties, rather than the fresh literal check. The fix works because excess property checks are a lint-like feature for catching typos and misaligned APIs in inline object definitions; they don't apply to variables passed by reference, allowing flexible object reuse while maintaining strictness for direct API calls.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T18:42:26.068527+00:00— report_created — created