@@ -110,9 +110,14 @@ export function processDeclarations(
110110 }
111111 }
112112
113- // Check which imports are needed for interfaces and types (only exported ones)
113+ // Check which imports are needed for interfaces and types (including non- exported ones that are referenced by exported items )
114114 for ( const iface of interfaces ) {
115- if ( iface . isExported ) {
115+ // Include interface if it's exported OR if it's referenced by exported functions
116+ const isReferencedByExports = functions . some ( func =>
117+ func . isExported && func . text . includes ( iface . name )
118+ )
119+
120+ if ( iface . isExported || isReferencedByExports ) {
116121 for ( const imp of imports ) {
117122 const importMatch = imp . text . match ( / i m p o r t \s + (?: t y p e \s + ) ? \{ ? \s * ( [ ^ } ] + ) \s * \} ? \s + f r o m / )
118123 if ( importMatch ) {
@@ -176,7 +181,7 @@ export function processDeclarations(
176181 }
177182 }
178183
179- // Create filtered imports based on actually used items
184+ // Create filtered imports based on actually used items
180185 const processedImports : string [ ] = [ ]
181186 for ( const imp of imports ) {
182187 const importMatch = imp . text . match ( / i m p o r t \s + (?: t y p e \s + ) ? \{ ? \s * ( [ ^ } ] + ) \s * \} ? \s + f r o m \s + [ ' " ] ( [ ^ ' " ] + ) [ ' " ] / )
@@ -189,11 +194,12 @@ export function processDeclarations(
189194
190195 if ( usedItems . length > 0 ) {
191196 const source = importMatch [ 2 ]
192- const hasTypeImports = usedItems . some ( item => item . startsWith ( 'type ' ) )
193- const hasValueImports = usedItems . some ( item => ! item . startsWith ( 'type ' ) )
197+
198+ // Check if original import was type-only
199+ const isOriginalTypeOnly = imp . text . includes ( 'import type' )
194200
195201 let importStatement = 'import '
196- if ( hasTypeImports && ! hasValueImports ) {
202+ if ( isOriginalTypeOnly ) {
197203 importStatement += 'type '
198204 }
199205 importStatement += `{ ${ usedItems . join ( ', ' ) } } from '${ source } ';`
0 commit comments