• Error
  • Reported by the binder

TS1102

'delete' cannot be called on an identifier in strict mode.

`delete` is applied to a plain variable name in strict-mode code. Delete object properties only; set variables to `undefined` instead.

What it means

In strict mode, delete can only remove properties (delete obj.key). Deleting a variable name is an error. ts-r-check also reports TS2703 for the same expression, because the operand isn't a property reference.

Example

index.ts
let x = 1;
delete x;
export {};
ts-r-check -p tsconfig.json --pretty false ts-r output
index.ts(2,8): error TS1102: 'delete' cannot be called on an identifier in strict mode.
index.ts(2,8): error TS2703: The operand of a 'delete' operator must be a property reference.

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

  • To clear a variable, assign undefined or null to it.
  • If the value is a property, delete the property: delete obj.x.