TypeScript Compiler Diagnostics
TS2353: Excess property in object literal
A fresh object literal is checked for unexpected properties when assigned to a known object type. Here the extra theme property is not part of the width-only contract; omit it if unnecessary or extend the contract if the property is genuinely supported. Structural assignability of a previously declared variable is not identical to fresh-literal checking, so moving the literal into a variable is not a reliable semantic fix. Baseline: TypeScript 5.8.3 with the shown configuration. Reproduce in one directory and create the corrected project in another. The diagnostic can have other causes; inspect its location and message before choosing a correction. Both projects keep strict checking enabled.
Formal Syntax & Structure
typescript syntaxtypescript
TS2353 (compiler diagnostic code, not TypeScript syntax)Working Example
Example Snippettypescript
// INTENTIONALLY INVALID — reproduce// File: tsconfig.json (omit this label){ "compilerOptions": { "strict": true, "target": "ES2022", "module": "CommonJS", "types": [], "lib": [ "ES2022", "DOM" ], "noEmitOnError": true, "outDir": "dist" }, "files": [ "main.ts" ]}
// File: main.ts (omit this label)type Options = { width: number };const options: Options = { width: 5, theme: "dark" };
// Run: tsc -p . --pretty false// Expected: TS2353; no output emitted.
// CORRECTED PROJECT — separate directory// File: tsconfig.json (omit this label){ "compilerOptions": { "strict": true, "target": "ES2022", "module": "CommonJS", "types": [], "lib": [ "ES2022", "DOM" ], "noEmitOnError": true, "outDir": "dist" }, "files": [ "main.ts" ]}
// File: main.ts (omit this label)type Options = { width: number };const options: Options = { width: 5 };console.log(options.width);
// Run: tsc -p . --pretty false// Expected: no diagnostics.// Run: node dist/main.js// Expected stdout: 5