@@ -9,6 +9,7 @@ export default (
99 c : GetConfig ,
1010 prior : ts . RefactorEditInfo ,
1111) : ts . RefactorEditInfo | undefined => {
12+ if ( actionName === 'Extract to typedef' ) return
1213 const extractToInterface = actionName === 'Extract to interface'
1314 if ( c ( 'codeActions.extractTypeInferName' ) && ( actionName === 'Extract to type alias' || extractToInterface ) ) {
1415 const changeFirstEdit = ( oldText : string , newTypeName : string ) => {
@@ -25,12 +26,15 @@ export default (
2526 if ( ! node ) return
2627 if ( ts . isAsExpression ( node ) || ts . isSatisfiesExpression ( node ) ) node = node . parent
2728 if ( ts . isVariableDeclaration ( node ) || ts . isParameter ( node ) || ts . isPropertyAssignment ( node ) || ts . isPropertySignature ( node ) ) {
28- let isWithinType = ts . isPropertySignature ( node )
29+ const isWithinType = ts . isPropertySignature ( node )
2930 if ( ts . isIdentifier ( node . name ) ) {
3031 const identifierName = node . name . text
3132 if ( ! identifierName ) return
3233 let typeName = identifierName [ 0 ] ! . toUpperCase ( ) + identifierName . slice ( 1 )
33- if ( ! isWithinType ) typeName += 'Type'
34+ const namePatternRaw = c ( 'codeActions.extractTypeInferNamePattern' )
35+ const namePatternSelected = typeof namePatternRaw === 'object' ? namePatternRaw [ extractToInterface ? 'interface' : 'typeAlias' ] : namePatternRaw
36+ // apply name pattern to type name
37+ typeName = tsFull . getUniqueName ( namePatternSelected . replaceAll ( '{{name}}' , typeName ) , sourceFile as FullSourceFile )
3438 const newFileEdit : ts . FileTextChanges = {
3539 fileName,
3640 textChanges : textChanges . map ( ( textChange , i ) => {
@@ -40,6 +44,8 @@ export default (
4044 }
4145 return {
4246 edits : [ newFileEdit ] ,
47+ renameFilename : fileName ,
48+ renameLocation : tsFull . getRenameLocation ( [ newFileEdit ] , fileName , typeName , /*preferLastLocation*/ false ) ,
4349 }
4450 }
4551 }
0 commit comments