• Error
  • Reported by the binder

TS1118

An object literal cannot have multiple get/set accessors with the same name.

An object literal has two getters (or two setters) for the same property. Keep one of each.

What it means

A property can have at most one get and one set accessor in an object literal. A second getter or setter with the same name is reported here; ts-r-check also reports TS2300 on both declarations.

Example

index.ts
const o = {
  get a() { return 1; },
  get a() { return 2; },
};
export {};
ts-r-check -p tsconfig.json --pretty false ts-r output
index.ts(2,7): error TS2300: Duplicate identifier 'a'.
index.ts(3,7): error TS1118: An object literal cannot have multiple get/set accessors with the same name.
index.ts(3,7): error TS2300: Duplicate identifier 'a'.

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

  • Delete one of the duplicate accessors.
  • A getter and a setter for the same name together are fine.