@@ -62,14 +62,16 @@ namespace ts.refactor.annotateWithTypeFromJSDoc {
62
62
const sourceFile = context . file ;
63
63
const token = getTokenAtPosition ( sourceFile , context . startPosition , /*includeJsDocComment*/ false ) ;
64
64
const decl = findAncestor ( token , isDeclarationWithType ) ;
65
- const jsdocType = getJSDocReturnType ( decl ) || getJSDocType ( decl ) ;
65
+ const jsdocType = getJSDocType ( decl ) ;
66
66
if ( ! decl || ! jsdocType || decl . type ) {
67
67
Debug . fail ( `!decl || !jsdocType || decl.type: !${ decl } || !${ jsdocType } || ${ decl . type } ` ) ;
68
68
return undefined ;
69
69
}
70
70
71
71
const changeTracker = textChanges . ChangeTracker . fromContext ( context ) ;
72
- changeTracker . replaceRange ( sourceFile , { pos : decl . getStart ( ) , end : decl . end } , addType ( decl , transformJSDocType ( jsdocType ) as TypeNode ) ) ;
72
+ const declarationWithType = addType ( decl , transformJSDocType ( jsdocType ) as TypeNode ) ;
73
+ suppressLeadingAndTrailingTrivia ( declarationWithType ) ;
74
+ changeTracker . replaceRange ( sourceFile , { pos : decl . getStart ( ) , end : decl . end } , declarationWithType ) ;
73
75
return {
74
76
edits : changeTracker . getChanges ( ) ,
75
77
renameFilename : undefined ,
@@ -87,7 +89,9 @@ namespace ts.refactor.annotateWithTypeFromJSDoc {
87
89
const token = getTokenAtPosition ( sourceFile , context . startPosition , /*includeJsDocComment*/ false ) ;
88
90
const decl = findAncestor ( token , isFunctionLikeDeclaration ) ;
89
91
const changeTracker = textChanges . ChangeTracker . fromContext ( context ) ;
90
- changeTracker . replaceRange ( sourceFile , { pos : decl . getStart ( ) , end : decl . end } , addTypesToFunctionLike ( decl ) ) ;
92
+ const functionWithType = addTypesToFunctionLike ( decl ) ;
93
+ suppressLeadingAndTrailingTrivia ( functionWithType ) ;
94
+ changeTracker . replaceRange ( sourceFile , { pos : decl . getStart ( ) , end : decl . end } , functionWithType ) ;
91
95
return {
92
96
edits : changeTracker . getChanges ( ) ,
93
97
renameFilename : undefined ,
0 commit comments