- Error
- Reported by the type checker
TS2353
Object literal may only specify known properties, and '{0}' does not exist in type '{1}'.
An object literal has a property its target type doesn't declare (an excess property). Remove it, fix its spelling, or add it to the type.
What it means
Object literals assigned directly to a typed target are checked for extra properties. Properties the target type doesn't know about are usually typos or leftovers.
Example
interface Options {
verbose?: boolean;
}
export const o: Options = { colour: true };
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(5,29): error TS2353: Object literal may only specify known properties, and 'colour' does not exist in type 'Options'.
Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.
How to fix
- Fix the spelling or remove the property. (When the name is close to a known property, the error is TS2561, which suggests it.)
- Add the property to the type if it belongs there.