TypeScript error

TS2362: Arithmetic on something that is not a number

  • Error TS2362
  • Tested with TypeScript 5.9

error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. and its twin TS2363 (the right-hand side) are reported for -, *, /, % and ** when an operand is not a number. JavaScript converts the operand silently at run time; the checker asks you to do it on purpose.

The two classic cases in JavaScript are subtracting Date objects to measure time (new Date() - startedAt), which works at run time through valueOf, and multiplying an input's value, which is a string. + is not on the list: with a string it concatenates, so it has its own message (TS2365) when it cannot apply.

At a glance

CodeTS2362
MessageThe left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
Also on this page: TS2363 The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
TypeScript's categoryerror
Listed underTypes do not match
Turned on by No option: every checked file reports it
In .js files Reported when the file is checked: checkJs in jsconfig.json, or // @ts-check at the top of the file

The messages are TypeScript's own text from its diagnostic messages file (Apache-2.0).

What it looks like

timer.js Error confirmed 5.9.3 TypeScript 5.9.3, run 21 October 2026: timer.js(4,26): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. timer.js(4,39): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. timer.js(7,40): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. timer.js(11,32): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. timer.js(4,26): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. timer.js(4,39): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. timer.js(7,40): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. timer.js(11,32): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. timer.js(4,26): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. timer.js(4,39): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. timer.js(7,40): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. timer.js(11,32): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. checked 21 October 2026
const startedAt = new Date();

export const elapsedMs = new Date() - startedAt;error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.

export const sinceStart = Date.now() - startedAt;error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.

const field = document.querySelector("input");
export const doubled = field ? field.value * 2 : 0;error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
Subtracting Date objects, and multiplying a form field's text.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": []
  },
  "include": ["*.js"]
}

What causes it

  • An operand is a Date: the checker does not apply valueOf for you.
  • An operand is a string, often input.value or a query parameter.
  • An operand may be undefined or null under strictNullChecks; that case is reported as TS18048 or TS18047 instead.

How to fix it

Convert the operand to a number

Use date.getTime() (or Date.now() for the current time) for dates, and Number(text) or input.valueAsNumber for form values. The result is the same number JavaScript would have used, now visible in the code.

timer.js TypeScript 5.9.3 TypeScript 5.9.3, run 21 October 2026: No errors. 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. No errors. 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. No errors. checked 21 October 2026
const startedAt = new Date();

export const elapsedMs = Date.now() - startedAt.getTime();

export const sinceStart = Date.now() - startedAt.valueOf();

const field = document.querySelector("input");
export const doubled = field ? Number(field.value) * 2 : 0;
Numbers on both sides of the operator.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": []
  },
  "include": ["*.js"]
}

Gotchas

  • Unary plus (+startedAt) also converts and the checker accepts it, but getTime() says what is meant.
  • Number("") is 0 and Number("abc") is NaN; the checker only sees number, so validate input before doing arithmetic with it.

Sources

Last reviewed 20 October 2026.