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

[method-signature-style] allow skip overload #4106

Closed
3 tasks done
loynoir opened this issue Nov 8, 2021 · 3 comments
Closed
3 tasks done

[method-signature-style] allow skip overload #4106

loynoir opened this issue Nov 8, 2021 · 3 comments
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin wontfix This will not be worked on

Comments

@loynoir
Copy link

loynoir commented Nov 8, 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

    "@typescript-eslint/method-signature-style": [
      "error"
    ],
export interface Foo {
  bar(): string;
  bar(x: number): any;
  bar(x: string): any;
  bar(x: string[]): any;
}

Expected Result

export interface Foo {
  bar(): string;
  bar(x: number): any;
  bar(x: string): any;
  bar(x: string[]): any;
}

Actual Result

eslint --fix

Unreadable output 😢

export interface Foo {
  bar: (() => string) & ((x: number) => any) & ((x: string) => any) & ((x: string[]) => any)
}

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin X.Y.Z
@typescript-eslint/parser X.Y.Z
TypeScript X.Y.Z
ESLint X.Y.Z
node X.Y.Z
@loynoir loynoir added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Nov 8, 2021
@bradzacher
Copy link
Member

Overloads are still methods. Ignoring them just because you might not like the alternative isn't a good idea because it introduces unsafety into the codebase (which is the opposite of what the rule enforces)

This is the easiest way to fix them.
You can use tools like prettier to format your code which would put them each on a new line, or you can do that manually. ESLint fixers do not care for formatting on purpose because everyone has different styles.

@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented Nov 8, 2021

That's... what the rule does, though? https://github.com/typescript-eslint/typescript-eslint/blob/076d65a/packages/eslint-plugin/docs/rules/method-signature-style.md#options

@loynoir have you read the docs? What's up?

Edit: hah, posted at ~ the same time.

@bradzacher bradzacher added wontfix This will not be worked on and removed triage Waiting for maintainers to take a look labels Nov 8, 2021
@loynoir
Copy link
Author

loynoir commented Nov 8, 2021

@JoshuaKGoldberg
Emm, @typescript-eslint/method-signature-style doesn't like overload method within class, and union all overload into one very long expression.

Overload is sometime complicated enough. I think readability first in that situation. Thus, suggest @typescript-eslint/method-signature-style to allow skiping overload.

Although in this short, no generic, similar length reproduce, prettier did some help.

export interface Foo {
  bar: (() => string) &
    ((x: number) => any) &
    ((x: string) => any) &
    ((x: string[]) => any);
}

My original case is a function wrapper. After prettier not helpful and some readings, I came here.

@bradzacher
I know it's not recommended, but in some situations I'm willing to take the risk to get more readability...

But, still OK to be closed.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants