Eslint-plugin-import: import/export: false positives for typescript overloads

Created on 12 May 2019  路  7Comments  路  Source: benmosher/eslint-plugin-import

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.

bug help wanted typescript

Most helpful comment

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.

All 7 comments

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

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.

I'm encountering the same issue.

Here's a workaround:

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

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

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

Agreed; a PR to fix it is welcome.

Was this page helpful?
0 / 5 - 0 ratings