diff --git a/packages/eslint-plugin/src/rules/consistent-type-imports.ts b/packages/eslint-plugin/src/rules/consistent-type-imports.ts index 9aaa296a4b0c..c23323411c66 100644 --- a/packages/eslint-plugin/src/rules/consistent-type-imports.ts +++ b/packages/eslint-plugin/src/rules/consistent-type-imports.ts @@ -261,17 +261,25 @@ export default util.createRule({ report.unusedSpecifiers.length === 0 && report.node.importKind !== 'type' ) { - context.report({ - node: report.node, - messageId: 'typeOverValue', - *fix(fixer) { - yield* fixToTypeImportDeclaration( - fixer, - report, - sourceImports, - ); - }, - }); + /** checks if import has type assertions + * ``` + * import * as type from 'mod' assert { type: 'json' }; + * ``` + * https://github.com/typescript-eslint/typescript-eslint/issues/7527 + */ + if (report.node.assertions.length === 0) { + context.report({ + node: report.node, + messageId: 'typeOverValue', + *fix(fixer) { + yield* fixToTypeImportDeclaration( + fixer, + report, + sourceImports, + ); + }, + }); + } } else { const isTypeImport = report.node.importKind === 'type'; @@ -612,7 +620,11 @@ export default util.createRule({ if (namespaceSpecifier && !defaultSpecifier) { // import * as types from 'foo' - yield* fixInsertTypeSpecifierForImportDeclaration(fixer, node, false); + + // checks for presence of import assertions + if (node.assertions.length === 0) { + yield* fixInsertTypeSpecifierForImportDeclaration(fixer, node, false); + } return; } else if (defaultSpecifier) { if ( diff --git a/packages/eslint-plugin/tests/rules/consistent-type-imports.test.ts b/packages/eslint-plugin/tests/rules/consistent-type-imports.test.ts index ae171e0d87e8..055f8473ee28 100644 --- a/packages/eslint-plugin/tests/rules/consistent-type-imports.test.ts +++ b/packages/eslint-plugin/tests/rules/consistent-type-imports.test.ts @@ -125,6 +125,16 @@ ruleTester.run('consistent-type-imports', rule, { `, options: [{ prefer: 'no-type-imports' }], }, + { + code: ` + import * as Type from 'foo' assert { type: 'json' }; + const a: typeof Type = Type; + `, + options: [{ prefer: 'no-type-imports' }], + dependencyConstraints: { + typescript: '4.5', + }, + }, ` import { type A } from 'foo'; type T = A; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy