@@ -215,6 +215,18 @@ module.exports = {
215
215
node . superTypeParameters . params . forEach ( markTypeAnnotationAsUsed ) ;
216
216
}
217
217
218
+ /**
219
+ * Checks the given expression and marks any type parameters as used.
220
+ * @param {ASTNode } node the relevant AST node.
221
+ * @returns {void }
222
+ * @private
223
+ */
224
+ function markExpressionAsUsed ( node ) {
225
+ if ( node . typeParameters && node . typeParameters . params ) {
226
+ node . typeParameters . params . forEach ( markTypeAnnotationAsUsed ) ;
227
+ }
228
+ }
229
+
218
230
/**
219
231
* Checks the given interface and marks it as used.
220
232
* Generic arguments are also included in the check.
@@ -236,19 +248,22 @@ module.exports = {
236
248
}
237
249
238
250
/**
239
- * Checks the given function return type and marks it as used.
251
+ * Checks the given function and marks return types and type parameter constraints as used.
240
252
* @param {ASTNode } node the relevant AST node.
241
253
* @returns {void }
242
254
* @private
243
255
*/
244
- function markFunctionReturnTypeAsUsed ( node ) {
256
+ function markFunctionOptionsAsUsed ( node ) {
257
+ if ( node . typeParameters && node . typeParameters . params ) {
258
+ node . typeParameters . params . forEach ( markTypeAnnotationAsUsed ) ;
259
+ }
245
260
if ( node . returnType ) {
246
261
markTypeAnnotationAsUsed ( node . returnType ) ;
247
262
}
248
263
}
249
264
250
265
/**
251
- * Checks the given class and marks super classes, interfaces and decoratores as used.
266
+ * Checks the given class and marks super classes, interfaces, type parameter constraints and decorators as used.
252
267
* @param {ASTNode } node the relevant AST node.
253
268
* @returns {void }
254
269
* @private
@@ -286,17 +301,12 @@ module.exports = {
286
301
}
287
302
} ,
288
303
289
- FunctionDeclaration : markFunctionReturnTypeAsUsed ,
290
- FunctionExpression : markFunctionReturnTypeAsUsed ,
291
- ArrowFunctionExpression : markFunctionReturnTypeAsUsed ,
304
+ FunctionDeclaration : markFunctionOptionsAsUsed ,
305
+ FunctionExpression : markFunctionOptionsAsUsed ,
306
+ ArrowFunctionExpression : markFunctionOptionsAsUsed ,
292
307
293
- CallExpression ( node ) {
294
- if ( node . typeParameters && node . typeParameters . params ) {
295
- node . typeParameters . params . forEach (
296
- markTypeAnnotationAsUsed
297
- ) ;
298
- }
299
- } ,
308
+ CallExpression : markExpressionAsUsed ,
309
+ NewExpression : markExpressionAsUsed ,
300
310
301
311
Decorator : markDecoratorAsUsed ,
302
312
TSInterfaceHeritage : markExtendedInterfaceAsUsed ,
0 commit comments