@@ -19,10 +19,17 @@ import {
1919import { resolveUnionType } from './unionTypeResolver' ;
2020import { getTypeName } from './common' ;
2121
22+ /**
23+ *
24+ * @param type TypeScript type to resolve
25+ * @param typeNode TypeScript TypeNode associated with the type, if available. It can be used to preserve the authored type name.
26+ * @param context Parser context containing TypeScript checker and other utilities.
27+ * @param skipResolvingComplexTypes If true, complex types like functions and objects will be resolved to their intrinsic types (e.g., 'function', 'object').
28+ */
2229export function resolveType (
2330 type : ts . Type ,
31+ typeNode : ts . TypeNode | undefined ,
2432 context : ParserContext ,
25- typeNode ?: ts . TypeNode ,
2633 skipResolvingComplexTypes : boolean = false ,
2734) : TypeNode {
2835 const { checker, typeStack, includeExternalTypes } = context ;
@@ -73,15 +80,19 @@ export function resolveType(
7380 namespaces ,
7481 declaration ?. constraint ?. getText ( ) ,
7582 declaration ?. default
76- ? resolveType ( checker . getTypeAtLocation ( declaration . default ) , context )
83+ ? resolveType ( checker . getTypeAtLocation ( declaration . default ) , undefined , context )
7784 : undefined ,
7885 ) ;
7986 }
8087
8188 if ( checker . isArrayType ( type ) ) {
8289 // @ts -expect-error - Private method
8390 const arrayType : ts . Type = checker . getElementTypeOfArrayType ( type ) ;
84- return new ArrayNode ( type . aliasSymbol ?. name , namespaces , resolveType ( arrayType , context ) ) ;
91+ return new ArrayNode (
92+ type . aliasSymbol ?. name ,
93+ namespaces ,
94+ resolveType ( arrayType , undefined , context ) ,
95+ ) ;
8596 }
8697
8798 if ( ! includeExternalTypes && isTypeExternal ( type , checker ) ) {
@@ -126,7 +137,7 @@ export function resolveType(
126137 const typeName = getTypeName ( type , typeSymbol , checker , false ) ;
127138
128139 for ( const memberType of type . types ) {
129- memberTypes . push ( resolveType ( memberType , context ) ) ;
140+ memberTypes . push ( resolveType ( memberType , undefined , context ) ) ;
130141 }
131142
132143 if ( memberTypes . length === 0 ) {
@@ -160,7 +171,7 @@ export function resolveType(
160171 return new TupleNode (
161172 typeSymbol ?. name ?? type . aliasSymbol ?. name ,
162173 namespaces ,
163- ( type as ts . TupleType ) . typeArguments ?. map ( ( x ) => resolveType ( x , context ) ) ?? [ ] ,
174+ ( type as ts . TupleType ) . typeArguments ?. map ( ( x ) => resolveType ( x , undefined , context ) ) ?? [ ] ,
164175 ) ;
165176 }
166177
@@ -235,14 +246,15 @@ export function resolveType(
235246 undefined ,
236247 [ ] ,
237248 [
238- resolveType ( ( type as ts . ConditionalType ) . resolvedTrueType ! , context ) ,
239- resolveType ( ( type as ts . ConditionalType ) . resolvedFalseType ! , context ) ,
249+ // TODO: Pass TypeNode here to resolve aliases correctly
250+ resolveType ( ( type as ts . ConditionalType ) . resolvedTrueType ! , undefined , context ) ,
251+ resolveType ( ( type as ts . ConditionalType ) . resolvedFalseType ! , undefined , context ) ,
240252 ] ,
241253 ) ;
242254 } else if ( conditionalType . resolvedTrueType ) {
243- return resolveType ( conditionalType . resolvedTrueType , context ) ;
255+ return resolveType ( conditionalType . resolvedTrueType , undefined , context ) ;
244256 } else if ( conditionalType . resolvedFalseType ) {
245- return resolveType ( conditionalType . resolvedFalseType , context ) ;
257+ return resolveType ( conditionalType . resolvedFalseType , undefined , context ) ;
246258 }
247259 }
248260
0 commit comments