@@ -216,11 +216,13 @@ export default (appDir: string, project: string) => {
216
216
. getTypeAtLocation ( node . body )
217
217
. getProperties ( )
218
218
. map ( p => {
219
- const typeNode = checker . typeToTypeNode (
220
- checker . getTypeOfSymbolAtLocation ( p , p . valueDeclaration ) ,
221
- undefined ,
222
- undefined
223
- )
219
+ const typeNode =
220
+ p . valueDeclaration &&
221
+ checker . typeToTypeNode (
222
+ checker . getTypeOfSymbolAtLocation ( p , p . valueDeclaration ) ,
223
+ undefined ,
224
+ undefined
225
+ )
224
226
225
227
return {
226
228
type : p . name as HooksEvent ,
@@ -266,14 +268,16 @@ export default (appDir: string, project: string) => {
266
268
. getProperties ( )
267
269
. map (
268
270
t =>
271
+ t . valueDeclaration &&
269
272
checker
270
273
. getSignaturesOfType (
271
274
checker . getTypeOfSymbolAtLocation ( t , t . valueDeclaration ) ,
272
275
ts . SignatureKind . Call
273
276
) [ 0 ]
274
277
. getReturnType ( )
275
278
. getSymbol ( )
276
- ?. getEscapedName ( ) === 'Promise' && t . name
279
+ ?. getEscapedName ( ) === 'Promise' &&
280
+ t . name
277
281
)
278
282
. filter ( ( n ) : n is string => ! ! n )
279
283
)
@@ -325,11 +329,13 @@ export default (appDir: string, project: string) => {
325
329
?. getReturnType ( )
326
330
. getProperties ( )
327
331
. map ( p => {
328
- const typeNode = checker . typeToTypeNode (
329
- checker . getTypeOfSymbolAtLocation ( p , p . valueDeclaration ) ,
330
- undefined ,
331
- undefined
332
- )
332
+ const typeNode =
333
+ p . valueDeclaration &&
334
+ checker . typeToTypeNode (
335
+ checker . getTypeOfSymbolAtLocation ( p , p . valueDeclaration ) ,
336
+ undefined ,
337
+ undefined
338
+ )
333
339
334
340
return {
335
341
type : p . name as HooksEvent ,
@@ -359,15 +365,16 @@ export default (appDir: string, project: string) => {
359
365
const genResSchemaText = ( method : LowerHttpMethod ) =>
360
366
`responseSchema${ controllers . filter ( c => c [ 2 ] ) . length } .${ method } `
361
367
const getSomeTypeQueryParams = ( typeName : string , query : ts . Symbol ) =>
368
+ query . valueDeclaration &&
362
369
checker
363
370
. getTypeOfSymbolAtLocation ( query , query . valueDeclaration )
364
371
. getProperties ( )
365
372
. map ( p => {
366
- const typeString = checker . typeToString (
367
- checker . getTypeOfSymbolAtLocation ( p , p . valueDeclaration )
368
- )
373
+ const typeString =
374
+ p . valueDeclaration &&
375
+ checker . typeToString ( checker . getTypeOfSymbolAtLocation ( p , p . valueDeclaration ) )
369
376
return typeString === typeName || typeString === `${ typeName } []`
370
- ? `['${ p . name } ', ${ p . declarations . some ( d =>
377
+ ? `['${ p . name } ', ${ ! ! p . declarations ? .some ( d =>
371
378
d . getChildren ( ) . some ( c => c . kind === ts . SyntaxKind . QuestionToken )
372
379
) } , ${ typeString === `${ typeName } []` } ]`
373
380
: null
@@ -377,7 +384,9 @@ export default (appDir: string, project: string) => {
377
384
results . push (
378
385
methods
379
386
. map ( m => {
380
- const props = checker . getTypeOfSymbolAtLocation ( m , m . valueDeclaration ) . getProperties ( )
387
+ const props = m . valueDeclaration
388
+ ? checker . getTypeOfSymbolAtLocation ( m , m . valueDeclaration ) . getProperties ( )
389
+ : [ ]
381
390
const query = props . find ( p => p . name === 'query' )
382
391
const numberTypeQueryParams = query && getSomeTypeQueryParams ( 'number' , query )
383
392
const booleanTypeQueryParams = query && getSomeTypeQueryParams ( 'boolean' , query )
@@ -389,16 +398,18 @@ export default (appDir: string, project: string) => {
389
398
. filter ( ( prop ) : prop is { name : string ; val : ts . Symbol } => ! ! prop . val )
390
399
. map ( ( { name, val } ) => ( {
391
400
name,
392
- type : checker . getTypeOfSymbolAtLocation ( val , val . valueDeclaration ) ,
393
- hasQuestion : val . declarations . some (
401
+ type :
402
+ val . valueDeclaration &&
403
+ checker . getTypeOfSymbolAtLocation ( val , val . valueDeclaration ) ,
404
+ hasQuestion : ! ! val . declarations ?. some (
394
405
d => d . getChildAt ( 1 ) . kind === ts . SyntaxKind . QuestionToken
395
406
)
396
407
} ) )
397
- . filter ( ( { type } ) => type . isClass ( ) )
408
+ . filter ( ( { type } ) => type ? .isClass ( ) )
398
409
399
410
const reqFormat = props . find ( p => p . name === 'reqFormat' )
400
411
const isFormData =
401
- ( reqFormat &&
412
+ ( reqFormat ?. valueDeclaration &&
402
413
checker . typeToString (
403
414
checker . getTypeOfSymbolAtLocation ( reqFormat , reqFormat . valueDeclaration )
404
415
) ) === 'FormData'
@@ -408,7 +419,7 @@ export default (appDir: string, project: string) => {
408
419
...genHookTexts ( 'onRequest' ) ,
409
420
...genHookTexts ( 'preParsing' ) ,
410
421
numberTypeQueryParams ?. length
411
- ? query ?. declarations . some (
422
+ ? query ?. declarations ? .some (
412
423
d => d . getChildAt ( 1 ) . kind === ts . SyntaxKind . QuestionToken
413
424
)
414
425
? `callParserIfExistsQuery(parseNumberTypeQueryParams([${ numberTypeQueryParams . join (
@@ -417,29 +428,31 @@ export default (appDir: string, project: string) => {
417
428
: `parseNumberTypeQueryParams([${ numberTypeQueryParams . join ( ', ' ) } ])`
418
429
: '' ,
419
430
booleanTypeQueryParams ?. length
420
- ? query ?. declarations . some (
431
+ ? query ?. declarations ? .some (
421
432
d => d . getChildAt ( 1 ) . kind === ts . SyntaxKind . QuestionToken
422
433
)
423
434
? `callParserIfExistsQuery(parseBooleanTypeQueryParams([${ booleanTypeQueryParams . join (
424
435
', '
425
436
) } ]))`
426
437
: `parseBooleanTypeQueryParams([${ booleanTypeQueryParams . join ( ', ' ) } ])`
427
438
: '' ,
428
- ...( isFormData && reqBody
439
+ ...( isFormData && reqBody ?. valueDeclaration
429
440
? [
430
441
'uploader' ,
431
442
`formatMulterData([${ checker
432
443
. getTypeOfSymbolAtLocation ( reqBody , reqBody . valueDeclaration )
433
444
. getProperties ( )
434
445
. map ( p => {
435
- const node = checker . typeToTypeNode (
436
- checker . getTypeOfSymbolAtLocation ( p , p . valueDeclaration ) ,
437
- undefined ,
438
- undefined
439
- )
446
+ const node =
447
+ p . valueDeclaration &&
448
+ checker . typeToTypeNode (
449
+ checker . getTypeOfSymbolAtLocation ( p , p . valueDeclaration ) ,
450
+ undefined ,
451
+ undefined
452
+ )
440
453
441
454
return node && ( ts . isArrayTypeNode ( node ) || ts . isTupleTypeNode ( node ) )
442
- ? `['${ p . name } ', ${ p . declarations . some ( d =>
455
+ ? `['${ p . name } ', ${ ! ! p . declarations ? .some ( d =>
443
456
d . getChildren ( ) . some ( c => c . kind === ts . SyntaxKind . QuestionToken )
444
457
) } ]`
445
458
: undefined
@@ -453,13 +466,14 @@ export default (appDir: string, project: string) => {
453
466
validateInfo . length
454
467
? `createValidateHandler(req => [
455
468
${ validateInfo
456
- . map (
457
- v =>
458
- ` ${
459
- v . hasQuestion ? `Object.keys(req.${ v . name } ).length ? ` : ''
460
- } validateOrReject(Object.assign(new Validators.${ checker . typeToString ( v . type ) } (), req.${
461
- v . name
462
- } ), validatorOptions)${ v . hasQuestion ? ' : null' : '' } `
469
+ . map ( v =>
470
+ v . type
471
+ ? ` ${
472
+ v . hasQuestion ? `Object.keys(req.${ v . name } ).length ? ` : ''
473
+ } validateOrReject(Object.assign(new Validators.${ checker . typeToString ( v . type ) } (), req.${
474
+ v . name
475
+ } ), validatorOptions)${ v . hasQuestion ? ' : null' : '' } `
476
+ : ''
463
477
)
464
478
. join ( ',\n' ) } \n ])`
465
479
: '' ,
0 commit comments