Skip to content

[Fix] no-import-module-exports: ignore type-only imports - #3309

Open
bardrop wants to merge 1 commit into
import-js:mainfrom
bardrop:fix-no-import-module-exports-type-imports
Open

bardrop wants to merge 1 commit into
import-js:mainfrom
bardrop:fix-no-import-module-exports-type-imports

Conversation

@bardrop

@bardrop bardrop commented Nov 11, 2026

Copy link
Copy Markdown

Fixes #2725.

import type (TS) and import type / import typeof (Flow) are erased at compile time, so they never end up mixing ESM with module.exports. In a CommonJS TS file they are also the only way to pull in types, so the rule was reporting code that has no real fix.

The rule now skips declarations whose importKind is type or typeof. Value imports in the same file are still reported. Inline specifiers (import { type Foo } from './foo') are still reported, since the declaration itself is not type-only and can survive as a side-effect import under verbatimModuleSyntax.

Tests cover the TS parsers (skipping typescript-eslint-parser, which predates type-only imports) and babel-eslint for Flow. I ran the rule tests on eslint 7, 8 and 9, and the full suite on eslint 8.

TypeScript `import type` and Flow `import type` / `import typeof` are
erased at compile time, so they never mix ESM imports with CommonJS
exports. They are also the only way to import types in a CommonJS file.

Fixes import-js#2725
@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.60%. Comparing base (a60d715) to head (c55d3f0).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3309   +/-   ##
=======================================
  Coverage   79.59%   79.60%           
=======================================
  Files          98       98           
  Lines        4549     4551    +2     
  Branches     1543     1576   +33     
=======================================
+ Hits         3621     3623    +2     
  Misses        928      928           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bardrop

bardrop commented Nov 19, 2026

Copy link
Copy Markdown
Author

Friendly ping when you have time. Is there anything you'd like changed here?

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

using 'import type' and module.exports in the same file should not raise an error for no-import-module-exports

1 participant