Skip to content
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-unused-vars] false positive when class property has the same name as import #2994

Open
3 tasks done
kmaraz opened this issue Feb 2, 2021 · 7 comments
Open
3 tasks done
Assignees
Labels
bug Something isn't working external This issue is with another package, not typescript-eslint itself package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@kmaraz
Copy link

kmaraz commented Feb 2, 2021

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

https://github.com/kmaraz/no-unused-vars-issue
I'll show you the issue in the pictures:
image
This works as the class property thisWorks has different name from the Test.
image
This does not work, as the class property Test has the same name as Test import.
Hope it helps! :)
Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 4.14.2
@typescript-eslint/parser 4.14.2
TypeScript 4.1.3
ESLint 7.18.0
node 14.15.0
@kmaraz kmaraz added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Feb 2, 2021
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for maintainers to take a look labels Feb 2, 2021
@bradzacher
Copy link
Member

I believe that the bug is here:

this.#referencer.currentScope().referenceDualValueType(identifier);

This is adding a reference to the Test value in the current scope.
However the current scope is the function scope - and the function scope has a Test variable defined (the parameter).
This should be referencing the value from the parent scope instead.

@splincode
Copy link

I same this issue:
Angular-RU/angular-ru-sdk#361

@bradzacher
Copy link
Member

This is a pretty complex problem to solve for all cases.
Name shadowing sucks to deal with.

On the one hand - one can naively fix this by placing the reference in the parent scope.
However this would then cause this case to break:

import { Test } from './Test';

declare function deco(..._param: any): any;

export class Clazz {
  @deco
  method<Test>(Test: Test) {}
}

I've opened an issue with TypeScript to clarify how it's supposed to work.

@bradzacher bradzacher self-assigned this Feb 6, 2021
@vegerot
Copy link
Contributor

vegerot commented Feb 12, 2021

I've opened an issue with TypeScript to clarify how it's supposed to work.

@bradzacher link to this issue?

@bradzacher
Copy link
Member

microsoft/TypeScript#42679

@vegerot
Copy link
Contributor

vegerot commented Feb 12, 2021

🙂 thanks

@bradzacher bradzacher added the external This issue is with another package, not typescript-eslint itself label May 15, 2021
@Woebin
Copy link

Woebin commented Feb 15, 2024

There was a response to the TypeScript issue logged by @bradzacher two weeks ago, see microsoft/TypeScript#42679 (comment) - the response states that the described behavior is expected.

Commenting to point this out as I'm seeing the same linting error as described here, using @typescript-eslint/eslint-plugin@6.7.5 - since this issue is still open, I'm guessing it's not considered resolved in a later version of the plugin either?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working external This issue is with another package, not typescript-eslint itself package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

5 participants