@@ -132,6 +132,7 @@ function getFix(first, rest, sourceCode, context) {
132132 const shouldAddDefault = getDefaultImportName ( first ) == null && defaultImportNames . size === 1 ;
133133 const shouldAddSpecifiers = specifiers . length > 0 ;
134134 const shouldRemoveUnnecessary = unnecessaryImports . length > 0 ;
135+ const preferInline = context . options [ 0 ] && context . options [ 0 ] [ 'prefer-inline' ] ;
135136
136137 if ( ! ( shouldAddDefault || shouldAddSpecifiers || shouldRemoveUnnecessary ) ) {
137138 return undefined ;
@@ -157,7 +158,6 @@ function getFix(first, rest, sourceCode, context) {
157158 ( [ result , needsComma , existingIdentifiers ] , specifier ) => {
158159 const isTypeSpecifier = specifier . importNode . importKind === 'type' ;
159160
160- const preferInline = context . options [ 0 ] && context . options [ 0 ] [ 'prefer-inline' ] ;
161161 // a user might set prefer-inline but not have a supporting TypeScript version. Flow does not support inline types so this should fail in that case as well.
162162 if ( preferInline && ( ! typescriptPkg || ! semver . satisfies ( typescriptPkg . version , '>= 4.5' ) ) ) {
163163 throw new Error ( 'Your version of TypeScript does not support inline type imports.' ) ;
@@ -186,6 +186,17 @@ function getFix(first, rest, sourceCode, context) {
186186
187187 const fixes = [ ] ;
188188
189+ if ( shouldAddSpecifiers && preferInline && first . importKind === 'type' ) {
190+ // `import type {a} from './foo'` → `import {type a} from './foo'`
191+ const typeIdentifierToken = tokens . find ( ( token ) => token . type === 'Identifier' && token . value === 'type' ) ;
192+ fixes . push ( fixer . removeRange ( [ typeIdentifierToken . range [ 0 ] , typeIdentifierToken . range [ 1 ] + 1 ] ) ) ;
193+
194+ const firstIdentifierTokens = tokens . filter ( ( token ) => firstExistingIdentifiers . has ( token . value ) ) ;
195+ for ( const identifier of firstIdentifierTokens ) {
196+ fixes . push ( fixer . replaceTextRange ( [ identifier . range [ 0 ] , identifier . range [ 1 ] ] , `type ${ identifier . value } ` ) ) ;
197+ }
198+ }
199+
189200 if ( shouldAddDefault && openBrace == null && shouldAddSpecifiers ) {
190201 // `import './foo'` → `import def, {...} from './foo'`
191202 fixes . push (
0 commit comments