目录

@typescript-eslint/no-base-to-string

Require .toString() to only be called on objects which provide useful information when stringified.

Rule Configuration

// code-linter.json5
{
  "rules": {
    "@typescript-eslint/no-base-to-string": "error"
  }
}

Options

For details, see @typescript-eslint/no-base-to-string.

Example of Correct Code

// These types all have useful .toString()s
const num = 123;
export const v1 = 'Text' + true;
export const v2 = `Value: ${num}`;
(() => {
  console.info('arrow function');
}).toString();

Example of Incorrect Code

interface MyType {
  name: string;
}
// Passing an object or class instance to string concatenation:
const obj: MyType = {
  name: 'object'
};
export const v1 = '' + obj;

class MyClass {}
const value = new MyClass();
export const v2 = value + '';

// Interpolation and manual .toString() calls too:
export const v3 = `Value: ${value}`;
export const v4 = obj.toString();

Rule Set

plugin:@typescript-eslint/all

For details about how to configure Code Linter check rules, see Code Linter.