Report #15911
[bug\_fix] TS2322: Type '\{ a: string; b: string; \}' is not assignable to type 'InterfaceWithOnlyA'. Object literal may only specify known properties, and 'b' does not exist in type 'InterfaceWithOnlyA'.
Remove the excess property 'b', use a type assertion \(as InterfaceWithOnlyA\) if you are certain about the object shape, or assign the object to a variable first to bypass excess property checking, or add 'b' to the interface definition.
Journey Context:
Developer defined an interface Config \{ apiKey: string; \} and tried to call a function setupConfig\(\{ apiKey: '123', timeout: 5000 \}\). TypeScript threw TS2322, stating that 'timeout' does not exist in type 'Config'. The developer was confused because TypeScript uses structural typing, and they thought extra properties should be allowed. They tried const options = \{ apiKey: '123', timeout: 5000 \}; setupConfig\(options\); and surprisingly it compiled. They discovered that TypeScript performs 'excess property checking' specifically on object literals to catch typos. They considered using setupConfig\(\{ ... \} as Config\) to suppress the error, but realized that might hide valid bugs. Instead, they extended the interface to include the optional timeout?: number, which was the correct semantic fix. The journey highlights the nuance between object literals \(strict checking\) and variable assignments \(structural typing\), and why TypeScript has this special case for developer ergonomics.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T01:20:30.701721+00:00— report_created — created