New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[no-invalid-this] incorrectly flagging class properties #491
Comments
Yes, this is because ESLint has no concept of class properties as they are only just (or not quite yet?) finalised. Either we'd have to wait for ESLint to implement it into the base rule, or create our own version of the rule within this plugin. I'd lean toward the former, as they should soon move to stage 4 (i'd hope) https://github.com/tc39/proposal-class-fields From the ESLint readme:
If it looks like it's going to be a while, we can consider bringing the rule in. |
It's unfortunate, because TypeScript allows to use features of stage >= 3. |
Happy to accept a PR with an extension rule if people don't want to wait for the official rule to be updated! |
This issue is tagged with "good first issue" – as someone who hasn't written an eslint rule before, how would an eslint-plugin noob get started? Forking eslint's no-invalid-this plugin and making some change to take advantage of the typescript parser? |
@bradzacher may I suggest https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/ROADMAP.md be updated. It's currently listed as
it should probably be
On another note. If this is implemented in typescript-eslint it would be helpful if
But state that it's not allowed as it's bound to the function and not the class. Or something like that :) |
That kind of code also reported incorrectly now. But I'm unsure this is incorrect behavior actually because this still function inside another function. But I think this is related to the issue. class Dog {
private debouncedBork = debounce(() => {
this.bork();
// ^^^^ Unexpected 'this'.eslint@typescript-eslint/no-invalid-this
});
} |
This comment has been minimized.
This comment has been minimized.
Please don't "bump" issues. It just creates notification spam and annoys everyone subscribed to the thread. We are a community maintained project - we rely upon contributions from the community to help move the project forward. |
Will be reconsidered when typescript-eslint/typescript-eslint#491 is fixed.
Will be reconsidered when <typescript-eslint/typescript-eslint#491> is addressed.
Just to give everyone an update here. I created a PR #2685 which should fix the issues reported here. |
Hello!
I've recently started migrating my projects from tslint to eslint (so far, successfully!!) but I've encountered one small issue with the
no-invalid-this
rule provided by eslint.Specifically, in a case similar to:
it will error due to the
this
being "invalid" (while the compiled code is totally valid).Is this a case of creating a specific @typescript-eslint-plugin rule for no-invalid-this?
Thanks!
The text was updated successfully, but these errors were encountered: