namespace ts . codefix { const errorCodes = [ Diagnostics . This_import_is_never_used_as_a_value_and_must_use_import_type_because_importsNotUsedAsValues_is_set_to_error . code ] ; const fixId = "convertToTypeOnlyImport" ; registerCodeFix ( { errorCodes , getCodeActions : function getCodeActionsToConvertToTypeOnlyImport ( context ) { const changes = textChanges . ChangeTracker . with ( context , t => { const importDeclaration = getImportDeclarationForDiagnosticSpan ( context . span , context . sourceFile ) ; fixSingleImportDeclaration ( t , importDeclaration , context ) ; } ) ; if ( changes . length ) { return [ createCodeFixAction ( fixId , changes , Diagnostics . Convert_to_type_only_import , fixId , Diagnostics . Convert_all_imports_not_used_as_a_value_to_type_only_imports ) ] ; } } , fixIds : [ fixId ] , getAllCodeActions : function getAllCodeActionsToConvertToTypeOnlyImport ( context ) { return codeFixAll ( context , errorCodes , ( changes , diag ) => { const importDeclaration = getImportDeclarationForDiagnosticSpan ( diag , context . sourceFile ) ; fixSingleImportDeclaration ( changes , importDeclaration , context ) ; } ) ; } } ) ; function getImportDeclarationForDiagnosticSpan ( span , sourceFile ) { return tryCast ( getTokenAtPosition ( sourceFile , span . start ) . parent , isImportDeclaration ) ; } function fixSingleImportDeclaration ( changes , importDeclaration , context ) { if ( ! importDeclaration ?. importClause ) { return ; } const { importClause } = importDeclaration ; changes . insertText ( context . sourceFile , importDeclaration . getStart ( ) + "import" . length , " type" ) ; if ( importClause . name && importClause . namedBindings ) { changes . deleteNodeRangeExcludingEnd ( context . sourceFile , importClause . name , importDeclaration . importClause . namedBindings ) ; changes . insertNodeBefore ( context . sourceFile , importDeclaration , factory . updateImportDeclaration ( importDeclaration , undefined , undefined , factory . createImportClause ( true , importClause . name , undefined ) , importDeclaration . moduleSpecifier , undefined ) ) ; } } }