diff --git a/packages/eslint-plugin/docs/rules/no-import-type-side-effects.md b/packages/eslint-plugin/docs/rules/no-import-type-side-effects.md index 4cc35547e6f..35b8f2c5282 100644 --- a/packages/eslint-plugin/docs/rules/no-import-type-side-effects.md +++ b/packages/eslint-plugin/docs/rules/no-import-type-side-effects.md @@ -6,7 +6,8 @@ description: 'Enforce the use of top-level import type qualifier when an import > > See **https://typescript-eslint.io/rules/no-import-type-side-effects** for documentation. -The [`--verbatimModuleSyntax`](https://www.typescriptlang.org/tsconfig#verbatimModuleSyntax) compiler option causes TypeScript to do simple and predictable transpilation on import declarations, namely it completely removes import declarations with a top-level `type` qualifier, and it removes any import specifiers with an inline `type` qualifier. +The [`--verbatimModuleSyntax`](https://www.typescriptlang.org/tsconfig#verbatimModuleSyntax) compiler option causes TypeScript to do simple and predictable transpilation on import declarations. +Namely, it completely removes import declarations with a top-level `type` qualifier, and it removes any import specifiers with an inline `type` qualifier. The latter behavior does have one potentially surprising effect in that in certain cases TS can leave behind a "side effect" import at runtime: @@ -20,7 +21,7 @@ import {} from 'mod'; import 'mod'; ``` -For some rare cases, this may be desirable - but for many cases you will not want to leave behind an unnecessary side effect import. +For the rare case of needing to import for side effects, this may be desirable - but for most cases you will not want to leave behind an unnecessary side effect import. ## Examples diff --git a/packages/eslint-plugin/src/rules/no-import-type-side-effects.ts b/packages/eslint-plugin/src/rules/no-import-type-side-effects.ts index ee2a4d3291e..f087ffe565f 100644 --- a/packages/eslint-plugin/src/rules/no-import-type-side-effects.ts +++ b/packages/eslint-plugin/src/rules/no-import-type-side-effects.ts @@ -26,19 +26,16 @@ export default util.createRule({ create(context) { const sourceCode = context.getSourceCode(); return { - ImportDeclaration(node): void { - if (node.importKind === 'type') { - return; - } + 'ImportDeclaration[importKind!="type"]'( + node: TSESTree.ImportDeclaration, + ): void { const specifiers: TSESTree.ImportSpecifier[] = []; for (const specifier of node.specifiers) { - if (specifier.type !== AST_NODE_TYPES.ImportSpecifier) { - return; - } - if (specifier.importKind !== 'type') { - return; - } + if ( + specifier.type !== AST_NODE_TYPES.ImportSpecifier || + specifier.importKind !== 'type' + ) { specifiers.push(specifier); }