• Error
  • Reported by the type checker

TS2362

The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.

The left operand of `-`, `*`, `/`, `%` or `**` isn't a number, bigint or enum. Convert it first.

What it means

Arithmetic operators other than + need numeric operands. A string, boolean, object or Date on the left is reported.

Example

index.ts
const start = new Date();

export const elapsed = start - 1;
ts-r-check -p tsconfig.json --pretty false ts-r output
index.ts(3,24): error TS2362: The left-hand side of an arithmetic operation 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 explicitly: start.getTime() - 1, Number(text) * 2.