How to fix The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type in TypeScript

TypeScriptINTERMEDIATEMEDIUMUpdated Dec 8, 2025· 130 views

TypeScript prevents arithmetic operations on invalid types like strings, booleans, and Date objects. This error enforces type safety by requiring operands to be number, bigint, enum, or any types.

Quick fix

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

// Incorrect - causes TS2363 error
const result = 5 - '3';

// Correct - convert to number first
const result = 5 - Number('3');
const result2 = parseInt('10') + 5;
const result3 = parseFloat('3.14') * 2;
  1. Convert strings to numbers using Number() or parseInt()
  2. Use getTime() method for Date arithmetic
  3. Ensure variables have correct numeric types
  4. Type guard for union types before arithmetic
typescript — error
// Incorrect - causes TS2363 error
const result = 5 - '3';
// Correct - convert to number first
const result = 5 - Number('3');
const result2 = parseInt('10') + 5;
const result3 = parseFloat('3.14') * 2;
The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type

What this error means

This error occurs when you attempt an arithmetic operation (addition, subtraction, multiplication, division, etc.) with operands that TypeScript doesn't consider valid for such operations. TypeScript's strict type checking ensures you only perform arithmetic on types that support mathematical operations. Invalid types include strings, booleans, objects, and Date objects, even though JavaScript allows implicit type coercion with some of these.

Typical symptoms

  • Arithmetic operations fail with TS2363 error on build or in your IDE
  • Operations involving string values (e.g., 5 - '3') show type errors
  • Subtracting or adding Date objects triggers the error
  • Using variables with union types that include non-numeric types fails
  • Code that works in plain JavaScript fails in TypeScript compilation

Common causes

  1. Attempting arithmetic with string operands without conversion (e.g., 5 - '3')
  2. Performing arithmetic directly on Date objects instead of their numeric values
  3. Using the capitalized 'Number' object type instead of lowercase 'number'
  4. Variables with union types that include strings, booleans, or other non-numeric types
  5. Forgetting to parse or convert user input or API responses to numbers

How to fix "The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type"

1Convert strings to numbers using Number() or parseInt()

If you have string operands, explicitly convert them to numbers before performing arithmetic operations:

typescript
// Incorrect - causes TS2363 error
const result = 5 - '3';

// Correct - convert to number first
const result = 5 - Number('3');
const result2 = parseInt('10') + 5;
const result3 = parseFloat('3.14') * 2;

Use Number() for general conversion, parseInt() for integers, or parseFloat() for decimal numbers.

2Use getTime() method for Date arithmetic

When performing arithmetic with Date objects, convert them to numbers using getTime() which returns milliseconds since Unix epoch:

typescript
// Incorrect - causes TS2363 error
const diff = new Date() - new Date('2024-01-01');

// Correct - use getTime()
const diff = new Date().getTime() - new Date('2024-01-01').getTime();

// Or use valueOf()
const diff2 = new Date().valueOf() - new Date('2024-01-01').valueOf();
3Ensure variables have correct numeric types

When declaring variables used in arithmetic, explicitly type them as number or bigint:

typescript
// Incorrect - implicit string type
const value = '42';
const result = 10 + value; // TS2363 error

// Correct - explicitly type as number
const value: number = 42;
const result = 10 + value;

// Or convert at usage
const value = '42';
const result = 10 + Number(value);
4Type guard for union types before arithmetic

If a variable has a union type that includes non-numeric types, use type guards before arithmetic:

typescript
// Incorrect - 'value' could be string
const value: number | string = getValue();
const result = value + 5; // TS2363 error

// Correct - type guard or assertion
const value: number | string = getValue();
if (typeof value === 'number') {
  const result = value + 5; // Safe now
}

// Or convert
const result = Number(value) + 5;
5Use bigint for large integer operations

If working with very large integers beyond JavaScript's safe integer limit, use bigint type:

typescript
// Regular number (safe up to 2^53 - 1)
const smallNum: number = 42;
const result1 = smallNum + 5;

// BigInt for larger numbers
const largeNum: bigint = 9007199254740991n;
const result2 = largeNum + 5n; // Must use bigint literals (n suffix)

// Can't mix number and bigint
const mixed = smallNum + largeNum; // TS2363 error - convert first
const correct = BigInt(smallNum) + largeNum;

Advanced notes

This is a deliberate type safety feature in TypeScript. Unlike JavaScript, which coerces types in arithmetic operations (e.g., '5' - 3 = 2), TypeScript requires explicit conversion to prevent subtle bugs. If you're migrating JavaScript to TypeScript, you may need to add type conversions throughout your codebase. Recent TypeScript versions (5.5+) improved handling of some edge cases, so consider upgrading if you encounter unexpected restrictions. For custom objects with numeric meaning, implement the valueOf() method, though TypeScript still won't allow direct arithmetic—you'll need to call valueOf() explicitly.

Frequently asked questions

What does "The right-hand side of an arithmetic operation must be of type 'any'," mean?
) with operands that TypeScript doesn't consider valid for such operations. TypeScript's strict type checking ensures you only perform arithmetic on types that support mathematical operations. Invalid types include strings, booleans, objects, and Date objects, even though JavaScript allows implicit type coercion with some of these.
How do I fix "The right-hand side of an arithmetic operation must be of type 'any',"?
TypeScript prevents arithmetic operations on invalid types like strings, booleans, and Date objects. This error enforces type safety by requiring operands to be number, bigint, enum, or any types.
What causes "The right-hand side of an arithmetic operation must be of type 'any',"?
Attempting arithmetic with string operands without conversion (e.g., 5 - '3') Performing arithmetic directly on Date objects instead of their numeric values Using the capitalized 'Number' object type instead of lowercase 'number'
Is the "The right-hand side of an arithmetic operation must be of type 'any'," error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading