Report #13097
[bug\_fix] Argument of type '\{ host: string; port: number; timeout: number; \}' is not assignable to parameter of type 'ServerConfig'. Object literal may only specify known properties, and 'timeout' does not exist in type 'ServerConfig'. ts\(2345\)
Add the excess property \('timeout'\) to the target type definition \(ServerConfig\), or if the property is intentionally extra and not consumed by the function, assign the object to a variable first \(const opts = \{ ... \}; func\(opts\);\) to bypass the fresh object literal check, or use a type assertion 'as ServerConfig' \(if you are sure\).
Journey Context:
You define an interface ServerConfig \{ host: string; port: number; \} and a function setup\(config: ServerConfig\). You try to call it with an object literal that includes an extra property: setup\(\{ host: 'localhost', port: 3000, timeout: 5000 \}\). TypeScript throws TS2345, stating 'timeout' does not exist in type 'ServerConfig'. Object literal may only specify known properties. You are confused because JavaScript allows extra properties. You search and learn about 'excess property checks', a TypeScript feature that only applies to fresh object literals assigned to typed locations to catch typos. You consider adding 'timeout' to the interface, but it's not part of the config. You try casting: setup\(\{ ... \} as ServerConfig\), which works but is unsafe. The robust fix is to either accept the extra property in the type using an index signature \[key: string\]: any, or more commonly, if you control the setup function and want to allow arbitrary options, you widen the type. However, the standard fix for the error as presented is to adjust the type definition or bypass the freshness check by assigning to an intermediate variable.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T17:45:28.413813+00:00— report_created — created