Why is this an issue?

An object that uses the default Object.prototype.toString() becomes "[object Object]" when converted to a string. Messages, logs, and generated text then show that placeholder instead of the data the code meant to include. Convert the value you want to show, usually one of the object’s properties.

This rule reports such objects in template literals, ` and `= concatenations, String(), toString() and toLocaleString() calls, Lodash _.toString(), and join() on arrays of them.

Noncompliant code example

The template literal converts the whole user object:

const user = { name: "Ada", id: 42 };
console.log(`Signed in: ${user}`); // Noncompliant: prints "Signed in: [object Object]"

Compliant solution

Interpolate the property the message needs:

const user = { name: "Ada", id: 42 };
console.log(`Signed in: ${user.name}`);

Define a toString() method instead when a class has one text form that every caller should get. To log the whole object, pass it as a separate argument, as in console.log("Signed in:", user), or use JSON.stringify(user). JSON.stringify throws on circular references and BigInt values, and omits functions and undefined properties.

Exceptions

The rule does not report a conversion that the surrounding code already guards. Any one of these guards is enough:

Error, RegExp, URL, and URLSearchParams values are not reported.

Resources

Documentation