Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[no-dupe-class-members] false negative for method overload #291

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

Closed
teppeis opened this issue Feb 17, 2019 · 4 comments · Fixed by #1492
Closed

[no-dupe-class-members] false negative for method overload #291

teppeis opened this issue Feb 17, 2019 · 4 comments · Fixed by #1492
Labels
enhancement: new base rule extension New base rule extension required to handle a TS specific case good first issue Good for newcomers has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@teppeis
Copy link
Contributor

teppeis commented Feb 17, 2019

Repro

{
  "rules": {
    "no-dupe-class-members": "error"
  }
}
class Foo {
  foo(a: string): string;
  foo(a: number): number;
  foo(a: any): any {}
}

Expected Result
no errors

Actual Result

  29:3  error  Duplicate name 'foo'  no-dupe-class-members
  30:3  error  Duplicate name 'foo'  no-dupe-class-members

Additional Info

no-dupe-class-members is a recommended rule in eslint, so many users enable it.

My suggestions:

A. disable in plugin:@typescript-eslint/recommended
B. create @typescript-eslint/no-dupe-class-members and add an option to allow overload in TypeScript
C. notice in document

Versions

package version
@typescript-eslint/eslint-plugin 1.3.0
@typescript-eslint/parser 1.3.0
TypeScript 3.3.3
ESLint 5.14.0
node 10.15.1
npm 6.8.0
@teppeis teppeis added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Feb 17, 2019
@teppeis teppeis changed the title [no-dupe-class-members] false positive for method overload [no-dupe-class-members] false negative for method overload Feb 17, 2019
@teppeis
Copy link
Contributor Author

teppeis commented Feb 17, 2019

tsc throws an error for duplicate methods without ESLint.

class Foo {
    bar() {}
    bar() {} // Error: Duplicate function implementation.
}

So no-dupe-class-members may not be necessary.

@mysticatea
Copy link
Member

Thank you for the report.

I think that we should have the setting to disable no-dupe-class-members rule in our recommended preset.

{
    "overrides": [
        {
            "files": ["*.ts", "*.tsx"],
            "rules": {
                "no-dupe-class-members": "off"
            }
        }
    ]
}

And we should not have any alternative rule since tsc checks it.

@armano2 armano2 added bug Something isn't working package: parser Issues related to @typescript-eslint/parser package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin and removed package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look package: parser Issues related to @typescript-eslint/parser labels Feb 19, 2019
@bradzacher bradzacher added the enhancement: new base rule extension New base rule extension required to handle a TS specific case label May 10, 2019
@brainkim
Copy link
Contributor

I’m not fond of the idea of merely relying on tsc compiler errors. Sometimes I’m using babel to compile typescript and it would be nice to be notified of dupe class members anyways.

@WORMSS
Copy link

WORMSS commented Feb 25, 2020

tsc throws an error for duplicate methods without ESLint.

class Foo {
    bar() {}
    bar() {} // Error: Duplicate function implementation.
}

So no-dupe-class-members may not be necessary.

Just to note, your test is not the same as OP

You have actually wrote two implementations, where as the OP as an single implementations with 2 overrides.

@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Feb 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: new base rule extension New base rule extension required to handle a TS specific case good first issue Good for newcomers has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants