diff --git a/packages/eslint-plugin/src/rules/consistent-type-exports.ts b/packages/eslint-plugin/src/rules/consistent-type-exports.ts index 324a622255d..f70d5961851 100644 --- a/packages/eslint-plugin/src/rules/consistent-type-exports.ts +++ b/packages/eslint-plugin/src/rules/consistent-type-exports.ts @@ -1,7 +1,6 @@ import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES, AST_TOKEN_TYPES } from '@typescript-eslint/utils'; -import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import { @@ -91,22 +90,18 @@ export default createRule({ function isSymbolTypeBased( symbol: ts.Symbol | undefined, ): boolean | undefined { - if (!symbol) { - return undefined; + while (symbol && symbol.flags & ts.SymbolFlags.Alias) { + symbol = checker.getAliasedSymbol(symbol); + if ( + symbol.getDeclarations()?.find(ts.isTypeOnlyImportOrExportDeclaration) + ) { + return true; + } } - - const aliasedSymbol = tsutils.isSymbolFlagSet( - symbol, - ts.SymbolFlags.Alias, - ) - ? checker.getAliasedSymbol(symbol) - : symbol; - - if (checker.isUnknownSymbol(aliasedSymbol)) { + if (!symbol || checker.isUnknownSymbol(symbol)) { return undefined; } - - return !(aliasedSymbol.flags & ts.SymbolFlags.Value); + return !(symbol.flags & ts.SymbolFlags.Value); } return { diff --git a/packages/eslint-plugin/tests/rules/consistent-type-exports.test.ts b/packages/eslint-plugin/tests/rules/consistent-type-exports.test.ts index 8508cd75ae7..b513411d676 100644 --- a/packages/eslint-plugin/tests/rules/consistent-type-exports.test.ts +++ b/packages/eslint-plugin/tests/rules/consistent-type-exports.test.ts @@ -64,6 +64,11 @@ export { NonTypeNS }; "export type * as foo from './consistent-type-exports/type-only-exports';", "export type * as foo from './consistent-type-exports/type-only-reexport';", "export * as foo from './consistent-type-exports/value-reexport';", + ` +import * as Foo from './consistent-type-exports'; +type Foo = 1; +export { Foo } + `, ], invalid: [ { @@ -483,5 +488,26 @@ export { export type * as foo from './consistent-type-exports/type-only-reexport'; `, }, + { + code: ` + import type * as Foo from './consistent-type-exports'; + type Foo = 1; + export { Foo }; + `, + errors: [ + { + column: 9, + endColumn: 24, + endLine: 4, + line: 4, + messageId: 'typeOverValue', + }, + ], + output: ` + import type * as Foo from './consistent-type-exports'; + type Foo = 1; + export type { Foo }; + `, + }, ], }); 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