- Error
- Reported by the type checker
TS2703
The operand of a 'delete' operator must be a property reference.
delete is applied to something that isn't a property, such as a variable. Only properties can be deleted; set a variable to undefined instead.
What it means
The delete operator removes a property from an object. Its operand must be a property access such as obj.key or obj[key].
Example
let value = 1;
delete (value + 1);
export {};
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.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
- Delete a property:
delete obj.key. - To clear a variable, assign
undefinedto it (and includeundefinedin its type).