TS2365

error TS2365: Operator ‘+’ cannot be applied to types ‘number’ and ‘object’.

Broken Code ❌

1
2
3
export function add(a: number, b: object): number {
return a + b;
}

Fixed Code ✔️

You can use the + operator only with equivalent data types (strings + strings or numbers + numbers):

1
2
3
export function add(a: number, b: number): number {
return a + b;
}