@@ -76,7 +76,7 @@ namespace ts.InlineHints {
76
76
}
77
77
78
78
const initializerType = checker . getTypeAtLocation ( decl . initializer ) ;
79
- const typeDisplayString = displayPartsToString ( typeToDisplayParts ( checker , initializerType ) ) ;
79
+ const typeDisplayString = printTypeInSingleLine ( initializerType ) ;
80
80
if ( typeDisplayString ) {
81
81
addTypeHints ( typeDisplayString , decl . name . end ) ;
82
82
}
@@ -143,11 +143,11 @@ namespace ts.InlineHints {
143
143
}
144
144
145
145
if ( valueDeclaration . type ) {
146
- return valueDeclaration . type . getText ( ) ;
146
+ return printNodeInSingleLine ( valueDeclaration . type ) ;
147
147
}
148
148
149
149
const signatureParamType = checker . getTypeOfSymbolAtLocation ( symbol , symbol . valueDeclaration ) ;
150
- return displayPartsToString ( typeToDisplayParts ( checker , signatureParamType ) ) ;
150
+ return printTypeInSingleLine ( signatureParamType ) ;
151
151
}
152
152
153
153
function truncation ( text : string , maxLength : number ) {
@@ -156,5 +156,38 @@ namespace ts.InlineHints {
156
156
}
157
157
return text ;
158
158
}
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
+ }
159
192
}
160
193
}
0 commit comments