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] Imports marked as unused if a method argument has the same name #2402

Closed
3 tasks done
ago1024 opened this issue Aug 19, 2020 · 1 comment
Closed
3 tasks done
Labels
duplicate This issue or pull request already exists package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin scope analyser Issues that are caused by bugs/incomplete cases in the scope analyser

Comments

@ago1024
Copy link

ago1024 commented Aug 19, 2020

  • I have first 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.

We're using TypeScript in an AngularJS project. The AngularJS dependency injection uses the argument names to inject the service. The registered service names and implementations usually have the same name. This results in function like those:

import { SomeService } from "./service";
function foo(SomeService: SomeService) {}

The import will be marked as unused by typescript/no-unused-vars

Repro
https://github.com/ago1024/typescript-eslint-unused-vars-import

{
    "env": {
        "browser": true,
        "es2020": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:@typescript-eslint/recommended"
    ],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaVersion": 11,
        "sourceType": "module"
    },
    "plugins": [
        "@typescript-eslint"
    ],
    "rules": {
        "no-unused-vars": "off"
    }
}
import { SomeService } from "./service";

export function query(SomeService: SomeService): string {
	return SomeService.query();
}

Expected Result

The imported SomeService type in test.ts:1 should not be marked as unused.

Actual Result

The SomeService import in line 1 is marked as unused

  1:10  warning  'SomeService' is defined but never used  @typescript-eslint/no-unused-vars

Versions

package version
@typescript-eslint/eslint-plugin 3.9.1
@typescript-eslint/parser 3.9.1
TypeScript 3.9.7
ESLint 7.7.0
node 10.14.1
@ago1024 ago1024 added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Aug 19, 2020
@bradzacher
Copy link
Member

#1856

@bradzacher bradzacher added duplicate This issue or pull request already exists scope analyser Issues that are caused by bugs/incomplete cases in the scope analyser and removed triage Waiting for maintainers to take a look labels Aug 19, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin scope analyser Issues that are caused by bugs/incomplete cases in the scope analyser
Projects
None yet
Development

No branches or pull requests

2 participants