目录

@typescript-eslint/no-this-alias

Disallow assigning this to variables.

This rule applies only to .js and .ts files.

Rule Configuration

// code-linter.json5
{
  "rules": {
    "@typescript-eslint/no-this-alias": "error"
  }
}

Options

For details, see @typescript-eslint/no-this-alias.

Example of Correct Code

const time = 1000;
export class CC {
  public doWork(): void {
    console.info('work');
  }

  public init(): void {
    setTimeout(function () {
      this.doWork();
    });
  }
}    

Example of Incorrect Code

// this cannot be assigned to a variable.
const self = this;

setTimeout(function () {
  self.doWork();
});

Rule Set

plugin:@typescript-eslint/recommended
plugin:@typescript-eslint/all

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