Repository navigation
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Author
|
Friendly ping when you have time. Is there anything you'd like changed here? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2725.
import type(TS) andimport type/import typeof(Flow) are erased at compile time, so they never end up mixing ESM withmodule.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
importKindistypeortypeof. 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 underverbatimModuleSyntax.Tests cover the TS parsers (skipping
typescript-eslint-parser, which predates type-only imports) andbabel-eslintfor Flow. I ran the rule tests on eslint 7, 8 and 9, and the full suite on eslint 8.