import-js/eslint-plugin-import

[import/no-unused-modules] Typescript `namespace` usage results in false positive

Open

#2,336 opened on Dec 24, 2021

View on GitHub
 (2 comments) (4 reactions) (0 assignees)JavaScript (1,540 forks)batch import
help wantedtypescript

Repository metrics

Stars
 (4,946 stars)
PR merge metrics
 (Avg merge 138d 22h) (3 merged PRs in 30d)

Description

// Foo.ts
export namespace MyNamespace {
  export interface Internal {
    a: string;
  }
}
// Bar.ts
import { MyNamespace } from 'Foo';

export const internal: MyNamespace.Internal = { a: 'a' };
/src/Foo.ts
  2:3  error  exported declaration 'Internal' not used within other modules      import/no-unused-modules

Both the export of MyNamepsace and Internal seem to be required for the usage to compile in Bar.ts. I think this kind of usage should not result in any errors. The namespace in Foo.ts can be replaced with the module keyword and the same false positive is raised.

This seems to be in a similar area to https://github.com/import-js/eslint-plugin-import/issues/1964 but with a different rule.

Contributor guide