- Error
- Reported by the type checker
TS2357
The operand of an increment or decrement operator must be a variable or a property access.
`++` or `--` is applied to something that isn't a variable or property, such as a call or a literal. Assign to a variable instead.
What it means
Increment and decrement change their operand, so the operand must be something that can be assigned to: a variable, a property or an element access.
Example
function count(): number {
return 1;
}
count()++;
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(5,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access.
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
- Store the value in a variable and increment that.