目录

@typescript-eslint/no-invalid-this

Disallow use of this in contexts where the value of this is undefined.

Rule Configuration

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

Options

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

Example of Correct Code

// Add "use strict" to the .ts file.
function baz(arg0: () => object) {
  return arg0;
}

export class Bar {
  public a: number;

  public constructor() {
    this.a = 0;
    baz(() => this);
  }
}

Example of Incorrect Code

// Add "use strict" to the .ts file.
function baz(arg0: () => object) {
  return arg0;
}

export function foo1() {
  this.a = 0;
  baz(() => this);
}

export const foo2 = () => {
  this.a = 0;
  baz(() => this);
};

Rule Set

plugin:@typescript-eslint/all

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