TS2362
TypeScript Programming Language
Severity: MinorWhat Does This Error Mean?
You used a non-number value in an arithmetic expression like + - or *. TypeScript requires both sides of arithmetic to be numeric types. Convert the value to a number before doing arithmetic on it.
Affected Models
- TypeScript 5.x
- TypeScript 4.x
- React + TypeScript
- Node.js + TypeScript
Common Causes
- Using a string in arithmetic — strings are not automatically converted to numbers in TypeScript
- Using an object or array in a math expression
- A variable typed as string | number being used directly in arithmetic without narrowing
- Forgetting to parse a value from a form input — HTML inputs return strings
- Using a boolean in an arithmetic expression without converting it first
How to Fix It
-
Convert the string to a number before using it in arithmetic.
Use Number(value), parseInt(value, 10) for integers, or parseFloat(value) for decimals.
-
If the variable is string | number, narrow it with a type guard first.
Example: if (typeof value === 'number') { result = value * 2; } — TypeScript knows it is a number inside.
-
For HTML form inputs, always parse the value before doing math.
input.value always returns a string. Use Number(input.value) or parseInt(input.value, 10) to convert.
-
Check if the value might be NaN after conversion and handle that case.
Number('abc') returns NaN. Add a check: if (!isNaN(num)) { ... } to guard against invalid input.
-
Fix the upstream type so the value is correctly typed as number from the start.
If a function returns string when it should return number, fix the return type to prevent the issue at the source.
When to Call a Professional
TS2362 is a straightforward compile-time error you can fix yourself. It usually reveals a place where a string-to-number conversion was forgotten.
Frequently Asked Questions
Why does JavaScript allow string arithmetic but TypeScript does not?
JavaScript silently converts types in arithmetic — this causes bugs like '5' + 3 = '53' instead of 8. TypeScript prevents this class of bug by requiring explicit conversions. The explicit conversion makes your intent clear and prevents surprises.
What is the difference between Number(), parseInt(), and parseFloat()?
Number() converts the whole value strictly — '3.14' becomes 3.14, '' becomes 0. parseInt() reads leading digits and ignores the rest — '42px' becomes 42. parseFloat() works like parseInt() but keeps decimal points. Choose based on what kind of number you expect.
Does the + operator cause TS2362 as well?
Not always — TypeScript allows string + string for concatenation. The + operator is overloaded for both addition and concatenation. TS2362 appears on operators like -, *, /, and % which are numeric-only.