- Error
- Reported by the type checker
TS2365
Operator '{0}' cannot be applied to types '{1}' and '{2}'.
A binary operator is used on two types it doesn't work with, like `+` on a number and an object, or `<` on a number and a string.
What it means
Operators such as +, <, >, <= and >= accept only some combinations of operand types. The message names the operator and both types.
Example
const a = 1;
const b = { value: 2 };
export const c = a + b;
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(4,18): error TS2365: Operator '+' cannot be applied to types '1' and '{ value: number; }'.
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
- Use the property you meant (
a + b.value), or convert the operands so both are numbers (or both strings).