@@ -276,7 +276,9 @@ module td
276276
277277
278278 function extractType ( target :Reflection , node :ts . Node , type :ts . Type ) :Type {
279- if ( type . flags & ts . TypeFlags . Intrinsic ) {
279+ if ( node && node [ 'typeName' ] && node [ 'typeName' ] . text && type && ( ! type . symbol || ( node [ 'typeName' ] . text != type . symbol . name ) ) ) {
280+ return new ReferenceType ( node [ 'typeName' ] . text , null , target . findReflectionByName ( node [ 'typeName' ] . text ) ) ;
281+ } else if ( type . flags & ts . TypeFlags . Intrinsic ) {
280282 return extractIntrinsicType ( < ts . IntrinsicType > type ) ;
281283 } else if ( type . flags & ts . TypeFlags . Enum ) {
282284 return extractEnumType ( type ) ;
@@ -308,19 +310,31 @@ module td
308310
309311 function extractTupleType ( target :Reflection , node :ts . TupleTypeNode , type :ts . TupleType ) :Type {
310312 var elements = [ ] ;
311- node . elementTypes . forEach ( ( elementNode ) => {
312- elements . push ( extractType ( target , elementNode , checker . getTypeAtLocation ( elementNode ) ) ) ;
313- } ) ;
313+ if ( node . elementTypes ) {
314+ node . elementTypes . forEach ( ( elementNode :ts . TypeNode ) => {
315+ elements . push ( extractType ( target , elementNode , checker . getTypeAtLocation ( elementNode ) ) ) ;
316+ } ) ;
317+ } else {
318+ type . elementTypes . forEach ( ( type :ts . Type ) => {
319+ elements . push ( extractType ( target , null , type ) ) ;
320+ } ) ;
321+ }
314322
315323 return new TupleType ( elements ) ;
316324 }
317325
318326
319327 function extractUnionType ( target :Reflection , node :ts . UnionTypeNode , type :ts . UnionType ) :Type {
320328 var types = [ ] ;
321- node . types . forEach ( ( typeNode :ts . TypeNode ) => {
322- types . push ( extractType ( target , typeNode , checker . getTypeAtLocation ( typeNode ) ) ) ;
323- } ) ;
329+ if ( node . types ) {
330+ node . types . forEach ( ( typeNode :ts . TypeNode ) => {
331+ types . push ( extractType ( target , typeNode , checker . getTypeAtLocation ( typeNode ) ) ) ;
332+ } ) ;
333+ } else {
334+ type . types . forEach ( ( type :ts . Type ) => {
335+ types . push ( extractType ( target , null , type ) ) ;
336+ } ) ;
337+ }
324338
325339 return new UnionType ( types ) ;
326340 }
@@ -521,6 +535,7 @@ module td
521535 case ts . SyntaxKind . SetAccessor :
522536 return visitSetAccessorDeclaration ( < ts . SignatureDeclaration > node , scope ) ;
523537 case ts . SyntaxKind . CallSignature :
538+ case ts . SyntaxKind . FunctionType :
524539 return visitCallSignatureDeclaration ( < ts . SignatureDeclaration > node , < DeclarationReflection > scope ) ;
525540 case ts . SyntaxKind . IndexSignature :
526541 return visitIndexSignatureDeclaration ( < ts . SignatureDeclaration > node , < DeclarationReflection > scope ) ;
@@ -533,8 +548,10 @@ module td
533548 return visitTypeLiteral ( < ts . TypeLiteralNode > node , scope ) ;
534549 case ts . SyntaxKind . ExportAssignment :
535550 return visitExportAssignment ( < ts . ExportAssignment > node , scope ) ;
551+ case ts . SyntaxKind . TypeAliasDeclaration :
552+ return visitTypeAliasDeclaration ( < ts . TypeAliasDeclaration > node , scope ) ;
536553 default :
537- // console.log('Unhandeled: ' + ts.SyntaxKind[ node.kind] );
554+ // console.log('Unhandeled: ' + node.kind);
538555 return null ;
539556 }
540557 }
@@ -1009,6 +1026,23 @@ module td
10091026 }
10101027
10111028
1029+ /**
1030+ * Analyze the given type alias declaration node and create a suitable reflection.
1031+ *
1032+ * @param node The type alias declaration node that should be analyzed.
1033+ * @param scope The reflection representing the current scope.
1034+ * @return The resulting reflection or NULL.
1035+ */
1036+ function visitTypeAliasDeclaration ( node :ts . TypeAliasDeclaration , scope :ContainerReflection ) :Reflection {
1037+ var alias = createDeclaration ( scope , node , ReflectionKind . TypeAlias ) ;
1038+ alias . type = extractType ( alias , node . type , checker . getTypeAtLocation ( node . type ) ) ;
1039+ if ( alias . name == 'Callback' ) {
1040+ // console.log(alias);
1041+ }
1042+ return alias ;
1043+ }
1044+
1045+
10121046 function visitExportAssignment ( node :ts . ExportAssignment , scope :ContainerReflection ) :Reflection {
10131047 var type = checker . getTypeAtLocation ( node . exportName ) ;
10141048 if ( type && type . symbol ) {
0 commit comments