Skip to content

[export] “Multiple exports” false positive on merged class and namespace #1964

Closed
@andersk

Description

@andersk
Contributor
// foo.ts
export class Foo {
  bar: string;
  constructor(options: Foo.Options) {
    this.bar = options.bar;
  }
}

export namespace Foo {
  export interface Options {
    bar: string;
  }
}
{
  "parser": "@typescript-eslint/parser",
  "plugins": ["import"],
  "rules": {
    "import/export": "error"
  }
}
/tmp/test/foo.ts
  1:14  error  Multiple exports of name 'Foo'  import/export
  8:18  error  Multiple exports of name 'Foo'  import/export

✖ 2 problems (2 errors, 0 warnings)

TypeScript namespace merging should not be an error. This is similar to #1549, but that issue seems to be specific to default exports.

Activity

smac89

smac89 commented on Sep 14, 2021

@smac89

For me, the problem comes from doing something like:

export enum Sex {
    MALE,
    FEMALE,
}

export namespace Sex {
    export function parse(sex: string): Sex {
        switch (sex.toLowerCase()) {
            case 'male':
                return Sex.MALE;
            case 'female':
                return Sex.FEMALE
            default:
                return null;
        }
    }
}

The error is on the parse function inside the namespace even though it is being used in some other parts of the code.

ljharb

ljharb commented on Sep 14, 2021

@ljharb
Member

Setting aside that your example is biologically inaccurate, thanks for the additional reproduction code. I'd be happy to review a PR if someone has a solution.

added a commit that references this issue on Jan 27, 2022
e9518c4
httpete

httpete commented on Jul 19, 2022

@httpete

I am getting false positives as well, when exporting a type only export, it is being imported in another but it gets flagged.

ljharb

ljharb commented on Jul 19, 2022

@ljharb
Member

@httpete if you're on the latest version of the plugin and still having problems, please file a new issue.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @andersk@ljharb@httpete@smac89

      Issue actions

        [export] “Multiple exports” false positive on merged class and namespace · Issue #1964 · import-js/eslint-plugin-import