@@ -76,7 +76,7 @@ namespace ts.InlineHints {
7676 }
7777
7878 const initializerType = checker . getTypeAtLocation ( decl . initializer ) ;
79- const typeDisplayString = displayPartsToString ( typeToDisplayParts ( checker , initializerType ) ) ;
79+ const typeDisplayString = printTypeInSingleLine ( initializerType ) ;
8080 if ( typeDisplayString ) {
8181 addTypeHints ( typeDisplayString , decl . name . end ) ;
8282 }
@@ -143,11 +143,11 @@ namespace ts.InlineHints {
143143 }
144144
145145 if ( valueDeclaration . type ) {
146- return valueDeclaration . type . getText ( ) ;
146+ return printNodeInSingleLine ( valueDeclaration . type ) ;
147147 }
148148
149149 const signatureParamType = checker . getTypeOfSymbolAtLocation ( symbol , symbol . valueDeclaration ) ;
150- return displayPartsToString ( typeToDisplayParts ( checker , signatureParamType ) ) ;
150+ return printTypeInSingleLine ( signatureParamType ) ;
151151 }
152152
153153 function truncation ( text : string , maxLength : number ) {
@@ -156,5 +156,38 @@ namespace ts.InlineHints {
156156 }
157157 return text ;
158158 }
159+
160+ function createSignleLineWriter ( writer : DisplayPartsSymbolWriter ) : DisplayPartsSymbolWriter {
161+ return {
162+ ...writer ,
163+ writeLine : ( ) => writer . writeSpace ( " " )
164+ } ;
165+ }
166+
167+ function printTypeInSingleLine ( type : Type ) {
168+ const flags = NodeBuilderFlags . IgnoreErrors | TypeFormatFlags . AllowUniqueESSymbolType | TypeFormatFlags . UseAliasDefinedOutsideCurrentScope ;
169+ const displayParts = mapToDisplayParts ( writer => {
170+ const singleLineWriter = createSignleLineWriter ( writer ) ;
171+ const typeNode = checker . typeToTypeNode ( type , /*enclosingDeclaration*/ undefined , flags , singleLineWriter ) ;
172+ Debug . assertIsDefined ( typeNode , "should always get typenode" ) ;
173+
174+ writeNodeInSignleLine ( typeNode , singleLineWriter ) ;
175+ } ) ;
176+ return displayPartsToString ( displayParts ) ;
177+ }
178+
179+ function printNodeInSingleLine ( node : Node ) {
180+ const displayParts = mapToDisplayParts ( writer => {
181+ const singleLineWriter = createSignleLineWriter ( writer ) ;
182+ writeNodeInSignleLine ( node , singleLineWriter ) ;
183+ } ) ;
184+ return displayPartsToString ( displayParts ) ;
185+ }
186+
187+ function writeNodeInSignleLine ( node : Node , writer : DisplayPartsSymbolWriter ) {
188+ const options : PrinterOptions = { removeComments : true } ;
189+ const printer = createPrinter ( options ) ;
190+ printer . writeNode ( EmitHint . Unspecified , node , /*sourceFile*/ file , writer ) ;
191+ }
159192 }
160193}
0 commit comments