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

import/export: false positives for typescript overloads #1357

Closed
Philipp91 opened this issue May 12, 2019 · 7 comments · Fixed by #1412
Closed

import/export: false positives for typescript overloads #1357

Philipp91 opened this issue May 12, 2019 · 7 comments · Fixed by #1412

Comments

@Philipp91
Copy link

Minimal example to reproduce (not a sensible use case for overloads, but anyway):

export function consume(val: number): void;
export function consume(val: string): void;
export function consume(val: number | string): void {
    // Do something.
}

All three consume will be annotated with error Multiple exports of name 'consume' import/export.

@ljharb
Copy link
Member

ljharb commented May 12, 2019

Actually do you need all the export keywords? I’d expect the first two to not need it.

@Philipp91
Copy link
Author

Sorry, I should have mentioned this. Leaving them off results in a TypeScript compiler error: TS2383: Overload signatures must all be exported or non-exported.

@leethree
Copy link

I'm encountering the same issue.

@matt-tingen
Copy link

Here's a workaround:

interface Consume {
  (val: number): void;
  (val: string): void;
}
export const consume: Consume = (val: number | string) => {
  // ...
}

@jose-nunez
Copy link

The interface workaround works for me and looks nicer than exporting all the overloads.
Thanks!

@tylerthehaas
Copy link

The work around is good and nice that there is an alternate syntax but the plugin should be able to handle all the features of typescript

@ljharb
Copy link
Member

ljharb commented Jun 12, 2019

Agreed; a PR to fix it is welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

6 participants