TS2362

error TS2362: The left-hand side of an arithmetic operation must be of type ‘any’, ‘number’, ‘bigint’ or an enum type.

Broken Code ❌

1
2
3
const userName = {name: 'Benny'};
const userAge = {age: 35};
const user = userName & userAge;

Fixed Code ✔️

When you want to merge two objects, you have a multitude of possibilities:

Spread Syntax

1
2
3
4
5
6
const userName = {name: 'Benny'};
const userAge = {age: 35};
const user = {
...userName,
...userAge
};

Object.assign

1
2
3
const userName = {name: 'Benny'};
const userAge = {age: 35};
const user = Object.assign({}, userName, userAge);