-
Notifications
You must be signed in to change notification settings - Fork 660
📎 Implement noThisAlias
, @typescript-eslint/no-this-alias
#4481
Comments
I have mixed feelings about this rule. I don't know how the TS eslint rule works, but in the web there are valid cases where this rule could create noise. Should the rule take in consideration those cases? What does this rule prevent? |
I think that the main reason of the existence of this rule is to detect cases where |
That's my main concern 😅 Given the following code: class B {
foo() {
const self = this;
window.addEventListener('click', function(evt) {
// do something with `this`
})
}
} How should the rule behave in this case? Suggesting a |
In the example do you mean |
Yeah sorry :) |
In this case, the function should be replaced by an arrow lambda and Thinking a bit more about this rule, this could be decomposed into two rules:
|
Actually, sorry. I was wrong. I meant The event listener binds the scope of
I like your proposal very much! Narrow use cases, one rule for each one! |
Description
Implement the recommended ESLint rule @typescript-eslint/no-this-alias.
Note that, we should accept restructuring assignment such as
const { props, state } = this
.The text was updated successfully, but these errors were encountered: