Skip to content

no-this-alias

Reports const self = this, let self = this and self = this: a variable that holds this. Destructuring this (const { x } = this) is not reported.

The alias is a leftover of code that needed this inside a function that has its own this. An arrow function takes the this of the surrounding code without it, and the alias lets a reader take self for something other than this.

To fix, use an arrow function, or bind.

Reported
...
function local(require: (id: string) => void) { require("d"); }
const self = this, { x } = this;
y = this;
...
function f(): void;
...
js:
lint:
rules:
no-this-alias: warn # off (default), warn, error

Enabled by the presets: js/typescript-eslint-recommended, js/biome-recommended, js/oxlint.

Suppress one line with sudsy-disable-next-line no-this-alias in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
typescript-eslint no-this-alias partial the options (allowDestructuring, allowedNames) keep their defaults