close

no-this-alias

Configuration

PresetConfigured Value
✅ ts.configs.recommended"error"
rslint.config.ts
import { defineConfig, ts } from '@rslint/core';

export default defineConfig([
  ts.configs.recommended,
  {
    rules: {
      '@typescript-eslint/no-this-alias': 'error',
    },
  },
]);

Rule Details

Disallow aliasing this.

Assigning this to a variable (commonly named self or that) is a legacy pattern that predates arrow functions. Arrow functions automatically capture the surrounding this, making this aliasing unnecessary.

Examples of incorrect code for this rule:

const self = this;
let that = this;
const foo = this;

Examples of correct code for this rule:

const { foo } = this; // destructuring is allowed by default
setTimeout(() => {
  this.doSomething(); // use arrow function instead of aliasing
});

Original Documentation