Skip to content

thisAliases

Reports assigning this to a variable.

✅ This rule is included in the ts logical presets.

Before ES2015, a common pattern was to assign this to a variable (often named self, that, or _this) to preserve the context when using function expressions. With arrow functions, this pattern is no longer necessary because arrow functions automatically preserve the surrounding this context.

class Example {
value = 10;
method() {
const self = this;
setTimeout(function () {
console.log(self.value);
}, 100);
}
}

Destructuring properties from this is allowed because it’s extracting specific values, not aliasing the context:

class Component {
props = { title: "Hello" };
state = { count: 0 };
render() {
const { props, state } = this;
return `${props.title}: ${state.count}`;
}
}

This rule is not configurable.

If you’re maintaining legacy code that heavily uses this aliasing and refactoring to arrow functions would be too costly, you might need to disable this rule.

Made with ❤️‍🔥 around the world by the Flint team and contributors.