@@ -409,6 +409,42 @@ function convertTypeAlias(
409
409
}
410
410
}
411
411
412
+ function convertTypeAliasFromValueDeclaration (
413
+ context : Context ,
414
+ symbol : ts . Symbol ,
415
+ exportSymbol : ts . Symbol | undefined ,
416
+ valueKind : ReflectionKind ,
417
+ ) : undefined {
418
+ const comment = context . getComment ( symbol , valueKind ) ;
419
+
420
+ const reflection = new DeclarationReflection (
421
+ exportSymbol ?. name || symbol . name ,
422
+ ReflectionKind . TypeAlias ,
423
+ context . scope ,
424
+ ) ;
425
+ reflection . comment = comment ;
426
+ context . postReflectionCreation ( reflection , symbol , exportSymbol ) ;
427
+ context . finalizeDeclarationReflection ( reflection ) ;
428
+
429
+ reflection . type = context . converter . convertType (
430
+ context . withScope ( reflection ) ,
431
+ context . checker . getTypeOfSymbol ( symbol ) ,
432
+ ) ;
433
+
434
+ if ( reflection . type . type === "reflection" && reflection . type . declaration . children ) {
435
+ // #2817 lift properties of object literal types up to the reflection level.
436
+ const typeDecl = reflection . type . declaration ;
437
+ reflection . project . mergeReflections ( typeDecl , reflection ) ;
438
+ delete reflection . type ;
439
+
440
+ // When created any signatures will be created with __type as their
441
+ // name, rename them so that they have the alias's name as their name
442
+ for ( const sig of reflection . signatures || [ ] ) {
443
+ sig . name = reflection . name ;
444
+ }
445
+ }
446
+ }
447
+
412
448
function attachUnionComments (
413
449
context : Context ,
414
450
declaration : ts . TypeAliasDeclaration ,
@@ -495,6 +531,10 @@ function convertFunctionOrMethod(
495
531
symbol : ts . Symbol ,
496
532
exportSymbol ?: ts . Symbol ,
497
533
) : undefined | ts . SymbolFlags {
534
+ if ( isTypeOnlyExport ( exportSymbol ) ) {
535
+ return convertTypeAliasFromValueDeclaration ( context , symbol , exportSymbol , ReflectionKind . Function ) ;
536
+ }
537
+
498
538
// Can't just check method flag because this might be called for properties as well
499
539
// This will *NOT* be called for variables that look like functions, they need a special case.
500
540
const isMethod = ! ! (
@@ -573,7 +613,7 @@ function convertClassOrInterface(
573
613
exportSymbol ?: ts . Symbol ,
574
614
) {
575
615
const reflection = context . createDeclarationReflection (
576
- ts . SymbolFlags . Class & symbol . flags
616
+ ( ts . SymbolFlags . Class & symbol . flags ) && ! isTypeOnlyExport ( exportSymbol )
577
617
? ReflectionKind . Class
578
618
: ReflectionKind . Interface ,
579
619
symbol ,
@@ -618,7 +658,7 @@ function convertClassOrInterface(
618
658
619
659
context . finalizeDeclarationReflection ( reflection ) ;
620
660
621
- if ( classDeclaration ) {
661
+ if ( classDeclaration && reflection . kind === ReflectionKind . Class ) {
622
662
// Classes can have static props
623
663
const staticType = context . checker . getTypeOfSymbolAtLocation (
624
664
symbol ,
@@ -984,6 +1024,10 @@ function convertVariable(
984
1024
symbol : ts . Symbol ,
985
1025
exportSymbol ?: ts . Symbol ,
986
1026
) : undefined | ts . SymbolFlags {
1027
+ if ( isTypeOnlyExport ( exportSymbol ) ) {
1028
+ return convertTypeAliasFromValueDeclaration ( context , symbol , exportSymbol , ReflectionKind . Variable ) ;
1029
+ }
1030
+
987
1031
const declaration = symbol . getDeclarations ( ) ?. [ 0 ] ;
988
1032
989
1033
const comment = context . getComment ( symbol , ReflectionKind . Variable ) ;
@@ -1485,3 +1529,13 @@ function isFunctionLikeInitializer(node: ts.Expression): boolean {
1485
1529
1486
1530
return false ;
1487
1531
}
1532
+
1533
+ function isTypeOnlyExport ( symbol : ts . Symbol | undefined ) : boolean {
1534
+ if ( ! symbol ) return false ;
1535
+
1536
+ const declaration = symbol . declarations ?. [ 0 ] ;
1537
+ if ( ! declaration ) return false ;
1538
+ if ( ! ts . isExportSpecifier ( declaration ) ) return false ;
1539
+
1540
+ return declaration . isTypeOnly || declaration . parent . parent . isTypeOnly ;
1541
+ }
0 commit comments