• Error
  • Reported by the type checker

TS2356

An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type.

`++`, `--`, unary `-` or `~` is applied to a value that isn't a number, bigint or enum. Convert it first.

What it means

Arithmetic unary operators need a numeric operand. Applying them to a string, boolean or object is reported.

Example

index.ts
let label = "1";
label++;
export { label };
ts-r-check -p tsconfig.json --pretty false ts-r output
index.ts(2,1): error TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type.

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

  • Convert the value to a number first, or keep a separate numeric variable.